Install Sun/Oracle JDK on Ubuntu Linux (Update Alternatives)

Ubuntu uses the alternatives system to provide installed versions of programs and libraries that may exist in different versions or from different vendors.

The Java JDK is one of the applications provided that way. Unfortunately, the Oracle JDK is not available from the official repositories anymore and needs to be downloaded manually.

For Unbuntu, download the bin package for your architecture (32 or 64 bit), then make the file executable and execute it:

chmod +x jdk1.6.....bin
./jdk1.6.....bin

The file will unpack itself to a jdk1.6… sub folder in the current working directory. Now, move the directory to the default location:

mv jdk1.6..../ /usr/lib/jvm

Download a small script, make it executable and execute it:

wget http://download.nightlabs.de/shell/update-jdk-alternatives.sh
chmod +x update-jdk-alternatives.sh
sudo update-jdk-alternatives.sh /usr/lib/jvm/jdk1.6..../

It will update all alternatives available for the Java JDK to the location of the Oracle JDK with a high priority. Afterwards, the default JDK for the whole system will be the newly installed JDK.

Congratulations!