Installing Java(JDK) on Linux

Tested on Fedora 14 which by default comes with OpenJDK installed.

First check active Java Version:
[tarique@localhost ~]$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.1) (fedora-
OpenJDK Server VM (build 19.0-b06, mixed mode)

To replace OpenJDK with Sun’s JDK, first download the binary(jdk-6u23-linux-i586.bin, filename may vary based on the jdk version downloaded).
Then change the permission of the file to make it executable:
[tarique@localhost ~]$ cd Downloads/
[tarique@localhost Downloads]$ chmod 777 jdk-6u23-linux-i586.bin

Execute the binary:
[tarique@localhost Downloads]$ ./jdk-6u23-linux-i586.bin
This will unpack files into jdk1.6.0_23 folder.

Now move jdk1.6.0_23 folder to /usr/local.
/usr/local is a good place to put self compiled or third party programs.
Switch user to root to do this:
[tarique@localhost Downloads]$ su
[root@localhost Downloads]# mv jdk1.6.0_23/ /usr/local/

Create a symbolic link to /usr/local/jdk1.6.0_23 folder:
[root@localhost Downloads]# cd /usr/local
[root@localhost local]# ln -s jdk1.6.0_23 jdk

Now /usr/local/jdk is actually a soft link to the origial /usr/local/jdk1.6.0_23

The reason for doing this is we might want to update to a new version of JDK in the future and don’t want to manually change every single program setting that is dependant on JDK. Just think of changing 50 JAVA_HOME setting after each JDK update, scary ha? So in the future when we update to a new JDK, just update that symbolic link to get all other programs to use the new JDK.

Now we need to set the alternatives properly. First find the java executable:
[root@localhost local]# which java

So /usr/bin/java is the file that would be executed if java commands had been run.

Install a new alternative for java:
[root@localhost local]# alternatives --install /usr/bin/java java /usr/local/jdk/bin/java 100

Configure java alternatives:
[root@localhost local]# alternatives --config java
There are 3 programs which provide 'java'.
Selection Command
*+ 1 /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
2 /usr/lib/jvm/jre-1.5.0-gcj/bin/java
3 /usr/local/jdk/bin/java
Enter to keep the current selection[+], or type selection number:

Enter 3 here, that is the jdk we just installed.

Check java version again:
[root@localhost local]# java -version
java version "1.6.0_23"
Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
Java HotSpot(TM) Server VM (build 19.0-b09, mixed mode)

So JDK has been installed.

Now we need to set JAVA_HOME system variable.
/etc/profile is the file that holds system wide/global environment variables.
Open /etc/profile with a text editor and add the line JAVA_HOME=/usr/local/jdk below HISTSIZE which will look like:

And in the export line add JAVA_HOME which will look like:


One thought on “Installing Java(JDK) on Linux

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