It is so easy to install Java on Ubuntu now. On Ubuntu 7.04 (Feisty Fawn), follow these steps:
1) Make sure you have the right repositories on your sources.list file.
Edit your sources.list file the following way:
sudo gedit /etc/apt/sources.list
or if you are not using gnome (e.g. you are logged in through ssh):
sudo nano /etc/apt/sources.list
If the following lines are not already there, add them:
deb http://us.archive.ubuntu.com/ubuntu feisty main restricted
deb http://us.archive.ubuntu.com/ubuntu feisty universe multiverse
Save the file (in nano use Control-O to save and then Control-X to exit).
Now you need to tell the package manager to update it’s database:
sudo apt-get update
2) Install Java using apt-get
I currently have both Java 5 and Java 6 installed on my machine and it’s very easy to switch between the two. Java 6 has some nice goodies such as JSR-223 and better jconsole that I like to use.
For Java 5:
sudo apt-get install sun-java5-jre sun-java5-jdk sun-java5-plugin
For Java 6:
sudo apt-get install sun-java6-jre sun-java6-jdk sun-java6-plugin
There are other packages that you might be interested in:
- sun-java6-demo
- sun-java6-doc
- sun-java6-source
3) Verify installation
Verify that you have the correct version of java running:
java -version
For example, on my machine (yes, I call it tiwouj):

To see a list of the java versions that you have installed, you can use the following command (it’s a letter L at the end of the command):
update-java-alternatives -l
Here is my list:

This should show you a list of all the java alternatives you have installed. java-gcj is the free version of Java from the GNU project and comes installed by default with Ubuntu so you should see it. To switch to a different version, use the following command:
sudo update-java-alternatives -s <version-desired>
e.g:
sudo update-java-alternatives -s java-1.5.0-sun
Make sure it worked:
java -version
That’s it! How easy was that? You have to love apt-get.