Howto Install Sun’s Java 6 on Debain

This article is a short Tutorial on how to install Java 6 on a Machine running Debian (Lenny) OS. I will try to keep the Installation process as simple as possible so let’s get started…

Step 1: Add “non-free” parameter

If you haven’t already done so, you have to add the “non-free” parameter to your apt “sources.list”. So open up your sources.list normallly located in /etc/apt/sources.list like so

nano /etc/apt/sources.list

…if you did not modify your “sources.list” up to now it might look something like this…

# deb cdrom:[Debian GNU/Linux 5.0.4 _Lenny_ - Official i386 NETINST Binary-1 20100201-16:45]/ lenny main
# deb cdrom:[Debian GNU/Linux 5.0.4 _Lenny_ - Official i386 NETINST Binary-1 20100201-16:45]/ lenny main

deb http://ftp.de.debian.org/debian/ lenny main
deb-src http://ftp.de.debian.org/debian/ lenny main

deb http://security.debian.org/ lenny/updates main
deb-src http://security.debian.org/ lenny/updates main

…now you have to add the “non-free” parameter to the end of the deb and deb-src lines. After that your “sources.list” should look like:

# deb cdrom:[Debian GNU/Linux 5.0.4 _Lenny_ - Official i386 NETINST Binary-1 20100201-16:45]/ lenny main
# deb cdrom:[Debian GNU/Linux 5.0.4 _Lenny_ - Official i386 NETINST Binary-1 20100201-16:45]/ lenny main

deb http://ftp.de.debian.org/debian/ lenny main non-free
deb-src http://ftp.de.debian.org/debian/ lenny main  non-free

deb http://security.debian.org/ lenny/updates main
deb-src http://security.debian.org/ lenny/updates main

…save your modified “sources.list” file.

Step 2: Install Java

Before you can install the sun-java packages you have to update your package repository…

apt-get update

now you can install the java packages…

apt-get install sun-java6-jdk sun-java6-jre

Step 3: Make Sun Java theĀ preferred Java runtime

You can make the installed Java distribution the preferred Java runtime by using the “update-java-alternatives” command like so:

update-java-alternatives -s java-6-sun

This will make the newly installed Java runtime the standard Java runtime for your system.

Step 4: Set JAVA_HOME

Before we do anything else we set the JAVA_HOME environment variable so that other applications can find your java distribution. To to that you have to edit your “.bashrc” file located in your home directory. So open up your “.bashrc” file:

nano ~/.bashrc

…and add the following line to the end of your file

export JAVA_HOME=/usr/lib/jvm/java-6-sun

at this point I’m assuming that your distribution installed java in /usr/lib/jvm/java-6-sun which is the default behaviour. If that is not the case you have to replace the path with your installation path. Now you can try to log out and log in again to check if the JAVA_HOME is correctly set. After logging in again you just type…

echo $JAVA_HOME

if everything went right you should see the path that you set in your “.bashrc” earlier.

/usr/lib/jvm/java-6-sun

The approach discussed above will set the JAVA_HOME environment variable for your user only! So other users on the system cannot make use of your JAVA_HOME variable. To set the JAVA_HOME variable on a systemwide scale you have to edit the /etc/profile file. Setting the JAVA_HOME variable in the /etc/profile file will make it available to every user of the current system. The process of setting the JAVA_HOME variable is the same as described above, except that you use the /etc/profile file instead of the ~/.bashrc file in your users home directory.

Step 5: Check your Java Installation

If everything went right the command

java -version

…should yield the following output:

java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

… so that’s that…hope it helps…cya

Advertisements