Properly installing Oracle's JDK on CentOS, RHEL or Scientific Linux

(Daniel Pfeifer)

In a perfect world all Java programs work perfectly on any flavour of the Java Virtual Machine. Your application compiled on the IBM JDK should work fine on the Oracle VM and likewise a program compiled using the Oracle JDK should work on OpenJDK. Unfortunately, we don't live in a perfect world and although 99,9% of all Java developers never encounter any compatibility problems you may eventually find yourself installing a bundled Java application that uses VM-specific internal classes (which is never a good idea, but that's another story) and thus will magically fail when running on any "foreign" VM.

As all popular Linux distributions now have switched to delivering Java in the form of OpenJDK, we will have to jump through hoops to both install the Oracle JDK and make it play nice with the package repository so that any applications that depend on Java and that can be installed through yum will find your sideloaded JDK.

This guide specifically focuses on the enterprise flavours of Linux, i.e. Scientific Linux 6, CentOS 6 and of course the mother of them both, Red Hat Enterprise Linux 6.

What we will need are three things:

  • The Oracle JDK RPM itself (must be downloaded from Oracle)
  • The JPackage Utils (can be installed using yum)
  • The Sun (well, Oracle) Compatibility package

Let's start out by installing what we will need to have on the Linux box from it's own package repository. As root (or sudo) do:

sudo yum install jpackage-utils

Once this is done we will have to download the Oracle JDK Linux RPM binary from (this guide assumes the latest release of the 6.0-branch which, at the time of writing, is 1.6.0_37).

When you downloaded the RPM binary, unpack (yes, it's weird, just do it):

unzip jdk-6u37-linux-x64-rpm.bin

You will end up with a bunch of RPM files on your file system. Now if you only want the JDK (which contains the JRE) and want to skip the JavaDB-packages, just install the jdk RPM:

yum localinstall jdk-6u37-amd64.rpm

Now you should have JDK (and JRE) 6 installed on your machine. But that in itself won't make yum very happy, because if you then try to install a package that depends on Java (i.e. Tomcat), it will still try to install OpenJDK. This is where the Sun compatibility package comes it.

The original *-sun-compat package from jpackage seems to be a bit dated, so we need to find one that fits a newer version and as it turns out the guys from Scientific Linux seem to have more current Sun compatibility packages in their repository. Now depending on which version of Java you've installed you may have to do some Google searching to find whether a friendly soul has fixed a sun-compat package for your specific version, but for 1.6.0_37 we at least have one ;)

Now just do the last step needed:

yum localinstall

When the command completes, alternatives will show the Oracle JDK as your default provider for the commands java, javac, et cetara. Furthermore, when try to install Tomcat, it will just quietly accept your sideloaded Oracle JDK as a substitute to the java-1.6.0-openjdk-packages.

Good luck and enjoy! :-)