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

5 comments

  1. After following the steps above I had to perform the following additional steps on my system

    As root enter “update-alternatives –config -java” at the command prompt. That should bring up a dialog similar to the following
    ________________________________________________________________________________

    There are 4 alternatives which provide `java’.

    Selection Alternative
    ———————————————–
    1 /usr/bin/gij-4.3
    2 /usr/lib/jvm/java-gcj/jre/bin/java
    + 3 /usr/lib/jvm/java-6-openjdk/jre/bin/java
    * 4 /usr/lib/jvm/java-6-sun/jre/bin/java

    Press enter to keep the default[*], or type selection number:
    ________________________________________________________________________________

    in my case 3 was the original default, I then typed 4 and hit enter, which as you can see changed the default.

    In any case I was tearing my hair out before I stumbled across that bit there so here’s hoping it saves someone else some problems.

  2. Thanks for the article, this is just what I needed. I’d like to add one more detail – if another flavour of Java is already present in the system, when you run java -version you will see something else (ex: that you have GCJ).

    To address that, you need to tell the system which Java you want to use:
    #update-java-alternatives -s java-6-sun

    And if you’re using 1.5, the command would be:
    #update-java-alternatives -s java-1.5.0-sun

  3. Pingback: How can I install Oracle/SUN Java JDK in Debian Linux? - Admins Goodies

  4. Pingback: How can I install Oracle/SUN Java JDK in Debian Linux? - Admins Goodies


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s