Installing java from sun on the new Ubuntu 9.10

How do I install Sun Java Development Kit (JDK) and Java Runtime Environment (JRE) under Ubuntu Linux? It appears that there are multiple JRE installed by default under Ubuntu. How do I select and use Sun JRE only?

This is a tough question, yet here’s a simple answer, even for beginners.

Ubuntu Linux has following packages from Sun:

  • sun-java6-bin : Sun Java Runtime Environment (JRE) 6
  • sun-java6-demo : Sun Java Development Kit (JDK) 6 demos
  • sun-java6-jdk : Sun Java Development Kit (JDK) 6
  • sun-java6-jre : Sun Java Runtime Environment (JRE) 6
  • 1. Open a shell prompt (terminal) and type the following to install JDK and JRE:

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

    2. Ubuntu Linux comes with update-java-alternatives utility to updates all alternatives belonging to one runtime or development kit for the Java language.

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

    if that doesn’t work, just skip to the next step (you might not have any other version installed).

    3. You also need to edit a file called /etc/jvm. This file defines the default system JVM search order. Each JVM should list their JAVA_HOME compatible directory in this file. The default system JVM is the first one available from top to bottom. Open /etc/jvm

    sudo vi /etc/jvm

    I use mcedit, since vi is soooo out of this world!

    4. Make sure /usr/lib/jvm/java-6-sun is added to the top of JVM list (or first):


    5. You also need to setup JAVA_HOME and PATH variable. Open your $HOME/.bash_profile or /etc/profile (system wide) configuration. Open your .bash_profile file:

    vi $HOME/.bash_profile
    vi $HOME/.bashrc

    6. Append the following lines to the bash profile settings:

    export JAVA_HOME=/usr/lib/jvm/java-6-sun
    export PATH=$PATH:$JAVA_HOME/bin

    7. Now try to see if it worked:

    java -version


    Leave a Reply

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

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

    Google+ photo

    You are commenting using your Google+ 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 )


    Connecting to %s