Guide to install the java jdk in Ubuntu 64

Hi everyone. The following procedure has been followed to successfully install the Sun Java JDK in an Ubuntu 64 bits OS.

The Ubuntu version is 11.04.

The first thing is to do is to dowload the right version from the Oracle site.

Currently you can find the dowloads in the following link:

http://www.oracle.com/technetwork/java/javase/downloads/index.html

The installing instructions are quite good, so I recommend to take a look to them anyway.

Currently, you have to install the JDK “manually”, so you need to download the self extracting installer. In my case, I downloaded the file jdk-6u26-linux-x64.bin

Once downloaded do the following:

1. Obtain root privileges

sudo -s

2. Copy or move the installation file to /usr/local.

3. Position yourself in /usr/local

cd /usr/local

4. Change the mode of the file to be able to execute it.

chmod +x jdk-6u26-linux-x64.bin

5. Execute the installer

./jdk-6u26-linux-x64.bin

6. At this time, you ill have the java installation in a folder in /usr/local. In my case, the folder was:

/usr/local/jdk1.6.0_26/

7. Now, we want to use this version of Java instead the one provided with Ubuntu. You should to that using update-alternatives. Update-alternatives is a utility that allow us to handle virtual links for our applications.

By default, when you enter “java” as a command, Ubuntu finds it in the path /usr/bin/java.

/usr/bin/java results to be a link managed by update-alternatives.

You can use update-alternatives, so in case that you need to install a newer version of java, you can easily use the new version without much hassle.

Let’s start by registering the path that we want to use for java from now on:

sudo update-alternatives –install /usr/bin/java java /usr/local/jdk1.6.0_26/bin/java 2

Now, our new path is a registered alternative path for the command java, that will be accessed through the link /usr/bin/java.

8. Now, run the following:

sudo update-alternatives --config java

and select the desired path as the chosen alternative.

If everything went well, as soon as you call the command java -version, you will obtain the sun machine.

9. You may want to do something similar for the environmente variable JAVA_HOME. I propose you to do this:

sudo update-alternatives --install /usr/local/java_home java_home /usr/local/jdk1.6.0_26/

Now, edit the file /etc/environment, and add the following line:

JAVA_HOME="/usr/local/java_home"

Restart the machine, and now you have a JAVA_HOME environment variable that points to the right filesystem folder.

I hope that you will find this useful.

Leave a comment