Experiences of an Inland Empire Dad

How to Install Multiple Copies of Java (JDK) on Linux

It’s hard to find old versions of Java on Sun’s website. So it may be worthwhile for a Linux/Unix administrator to keep old copies at hand. Also, keeping several versions installed is relatively easy — once you know the version of Java you want.

Different Versions to Install

The Linux versions of JDK come in several forms. There’s the 32-bit and 64-bit version. For each of these, there’s the .bin version and the rpm.bin version.

Installing the .bin version is very easy. Just run the jdk--linux-i586.bin or the jdk--linux-amd64.bin file as root. Agree to Sun’s legal jargon, and it will create a version-specific jdk folder in your current directory. Move it anywhere you please (i.e. /usr/local/jdk).

Installing from RPM

Since I’m using a Red Hat Linux machine, I’ll go into detailed instructions for the rpm install. I’m upgrading from JDK 1.5.0_12 to JDK 1.5.0_16. J2SE 5.0 is reaching its end-of-life (EOL), but that’s a different story.

For this install, I’ll place the various versions of java in /usr/local/jdk

1) Download the correct version of Java. I’m using a 64-bit machine, so I downloaded jdk-1_5_0_16-linux-amd64-rpm.bin. If you’re using a 32-bit machine, it’d probably be labeled jdk-1_5_0_16-linux-i586.rpm.bin. I like to keep a copy in /usr/local/src.

2) Check your current version of Java

which java

/usr/bin/java

java -version

3) Set up your Java as a set of links, as follows:

ls /usr/bin/java

lrwxrwxrwx … /usr/bin/java -> /usr/local/java/bin/java

ls -l /usr/local/java

lrwxrwxrwx … /usr/local/java -> jdk1.5.0_12

4) Validate, install package in /usr/local, and verify your installation

cd /usr/local/src

rpm –checksig jdk-1_5_0_16-linux-amd64.rpm

mkdir /usr/java

rpm -i –relocate /usr/java=/usr/local jdk-1_5_0_16-amd64.rpm

rpm -q jdk

See the files associated with your jdk install

rpm -ql jdk

5) Point your default Java executable to your new install

cd /usr/local

rm java

ln -s jdk1.5.0_16 java

ls -l java

java -version