Sunday, July 29, 2012

Installing Oracle JDK 6 in Ubuntu 12.04

My Ubuntu customization continues this time with Java. Everyone should know that Ubuntu does not come with Oracle-Sun JDK anymore instead it comes with open-jdk which I like but the projects I am working on does need Oracle-Sun jdk and version 5 or 6 so I did not have an option to install it.

You can download the version you want for the architecture you need from Oracles web site. by the time of this post the version I used was jdk-6u33 but it should apply to any version.

JDK Download
The next step is to unpack the bin file. You do it by executing these 2 lines:
chmod +x jdk-6u33-linux-i586.bin

You will see a jdk-6u33-linux-i586 folder as result of the last

Third step is to move the folder to a safe and standard place. To do that we use the next command
sudo mv jdk-6u33-linux-i586 /usr/lib/jvm/
Next we create a symbolic link, you know so you do not have to type jdk-6u33-linux-i586 all the time. We do that by typing
cd /usr/lib/jvm/
sudo ln -s  jdk-6u33-linux-i586 java
Finally, you need to set the environment variables. In my case update them since I already had openjdk installed but it will work either you have or not another version installed before. You need to do it for both java and javac
sudo update-alternatives --config javac
sudo update-alternatives --config java
Default jdk
You will need to choose the the option to the Oracle-Sun jdk you want and press enter.

To test this out you just type
java -version
javac -version

checking versions
and you should see the version you installed.

There is an easy way to this which is adding an extra repository. There are tons of PPAs that come with Oracle-SUN JDK these days, but as you know I like to have control of these things. The easy way is like this
sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update

sudo apt-get install oracle-java6-installer

More information and nice guides can be found here, here and here.

Let me know if you have any questions.

Happy coding!

1 comment:

  1. should be
    sudo add-apt-repository ppa:webupd8team/java
    sudo add-apt-repository ppa:webup8team/java