How to install Java on Debian Lenny

Every time I have to install a new Debian system I end up going to half a dozen pages to find all the steps needed to add Java to the system. I usually want to have both Suns JDK and OpenJDK install so that I can switch between them. So here is how to go about installing them.

To install Suns JDK the contrib and non-free repositories to apt. To do this edit /etc/apt/sources.list and add contib non-free to the end of both deb and deb-src ftp repositories. When done the lines should look something like this:

Now run apt-get update to refresh the package list.

Next we will install Suns JDK. Run the command:

Follow the instructions on screen.

Next we need to install Open JDK. Run the command:

Next we need to make sure that the correct JDK is chosen by default when running java. This is done using update-alternatives command. Run the command:

Select the version you want to run. It is useful to remember this command for when you want to change JVM implementation.

That's it. Java is set up and ready to be used.