Oracle JDK on CentOS

Anand Bisen bio photo By Anand Bisen Comment

Lately I have been playing a lot with various applications that expects a proper installation of Oracle Java and not the default OpenJDK that Ubuntu and CentOS distribution ships with.

Just placing the files in any location and setting the PATH and JAVA_HOME works most of the time… But then by following simple procedure the installation could be made more complete such that man pages works the way they should, binaries like jps are accessible from non login shell (Which I need to test which Hadoop processes are running using pdsh) et. al..

Below I am just documenting the steps I take to get my JAVA installation performed cleanly on my nodes. Would love to get inputs on how this procedure could be improved

Step I: Download java binaries from As of the writing the following link works for getting to the landing page. You will have to accept the License Agreement and download the jdk-6u45-linux-x64.bin package.

Java Download

Step II: Once the package is on the host make it executable and extract the content by executing the binary.::

# chmod +x jdk-6u45-linux-x64.bin
# ./jdk-6u45-linux-x64.bin
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (
creating: jdk1.6.0_45/
creating: jdk1.6.0_45/db/
creating: jdk1.6.0_45/db/bin/
inflating: jdk1.6.0_45/db/bin/ij
Creating jdk1.6.0_45/jre/lib/plugin.jar
Creating jdk1.6.0_45/jre/lib/javaws.jar
Creating jdk1.6.0_45/jre/lib/deploy.jar


Step III: Now the resulting directory jdk1.6.0_45 should be moved to /usr/lib/jvm/ or any other location you would want to place it. And the as man pages should be gzipped I also gzip the man pages in order to be consistent.:

# mv jdk1.6.0_45 /usr/lib/jvm/
# gzip /usr/lib/jvm/jdk1.6.0_45/man/man1/*

Step IV: Now that everything is in place instead of editing /etc/profile.d or bashrc and modifying JAVA_HOME and PATH we will use update-alternatives which would make this JDK the default JAVA package to use system wide. For making this process repeatable I would suggest just creating a shell script with the content below and executing it.





$ALTERNATIVES --install $UBIN/java java $JBIN/java    $PRIORITY                   \
--slave $UBIN/javac                javac               $JBIN/javac                \
--slave $UBIN/javaws               javaws              $JBIN/javaws               \
--slave $UBIN/javadoc              javadoc             $JBIN/javadoc              \
--slave $UBIN/jar                  jar                 $JBIN/jar                  \
--slave $UBIN/keytool              keytool             $JBIN/keytool              \
--slave $UBIN/appletviewer         appletviewer        $JBIN/appletviewer         \
--slave $UBIN/javap                javap               $JBIN/javap                \
--slave $UBIN/jdb                  jdb                 $JBIN/jdb                  \
--slave $UBIN/jstat                jstat               $JBIN/jstat                \
--slave $UBIN/rmic                 rmic                $JBIN/rmic                 \
--slave $UBIN/idlj                 idlj                $JBIN/idlj                 \
--slave $UBIN/javah                javah               $JBIN/javah                \
--slave $UBIN/jstack               jstack              $JBIN/jstack               \
--slave $UBIN/orbd                 orbd                $JBIN/orbd                 \
--slave $UBIN/pack200              pack200             $JBIN/pack200              \
--slave $UBIN/rmid                 rmid                $JBIN/rmid                 \
--slave $UBIN/rmiregistry          rmiregistry         $JBIN/rmiregistry          \
--slave $UBIN/servertool           servertool          $JBIN/servertool           \
--slave $UBIN/tnameserv            tnameserv           $JBIN/tnameserv            \
--slave $UBIN/unpack200            unpack200           $JBIN/unpack200            \
--slave $UBIN/jps                  jps                 $JBIN/jps                  \
--slave $UBIN/apt                  apt                 $JBIN/apt                  \
--slave $MPATH/java.1.gz           java.1.gz           $JMPATH/java.1.gz          \
--slave $MPATH/javac.1.gz          javac.1.gz          $JMPATH/javac.1.gz         \
--slave $MPATH/javaws.1.gz         javaws.1.gz         $JMPATH/javaws.1.gz        \
--slave $MPATH/javadoc.1.gz        javadoc.1.gz        $JMPATH/javadoc.1.gz       \
--slave $MPATH/jar.1.gz            jar.1.gz            $JMPATH/jar.1.gz           \
--slave $MPATH/keytool.1.gz        keytool.1.gz        $JMPATH/keytool.1.gz       \
--slave $MPATH/appletviewer.1.gz   appletviewer.1.gz   $JMPATH/appletviewer.1.gz  \
--slave $MPATH/javap.1.gz          javap.1.gz          $JMPATH/javap.1.gz         \
--slave $MPATH/jdb.1.gz            jdb.1.gz            $JMPATH/jdb.1.gz           \
--slave $MPATH/jstat.1.gz          jstat.1.gz          $JMPATH/jstat.1.gz         \
--slave $MPATH/rmic.1.gz           rmic.1.gz           $JMPATH/rmic.1.gz          \
--slave $MPATH/idlj.1.gz           idlj.1.gz           $JMPATH/idlj.1.gz          \
--slave $MPATH/javah.1.gz          javah.1.gz          $JMPATH/javah.1.gz         \
--slave $MPATH/jstack.1.gz         jstack.1.gz         $JMPATH/jstack.1.gz        \
--slave $MPATH/orbd.1.gz           orbd.1.gz           $JMPATH/orbd.1.gz          \
--slave $MPATH/pack200.1.gz        pack200.1.gz        $JMPATH/pack200.1.gz       \
--slave $MPATH/rmid.1.gz           rmid.1.gz           $JMPATH/rmid.1.gz          \
--slave $MPATH/rmiregistry.1.gz    rmiregistry.1.gz    $JMPATH/rmiregistry.1.gz   \
--slave $MPATH/servertool.1.gz     servertool.1.gz     $JMPATH/servertool.1.gz    \
--slave $MPATH/tnameserv.1.gz      tnameserv.1.gz      $JMPATH/tnameserv.1.gz     \
--slave $MPATH/unpack200.1.gz      unpack200.1.gz      $JMPATH/unpack200.1.gz     \
--slave $MPATH/jps.1.gz            jps.1.gz            $JMPATH/jps.1.gz           \
--slave $MPATH/apt.1.gz            apt.1.gz            $JMPATH/apt.1.gz


Step V: Now the last step is to make this installation the default one to be used. If you already have OpenJDK installed it’s likely that you already have that configured as default. Let’s change it… And then validate if we can use the newly installed package.:

[root@cdh ~]# update-alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
  +  1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
     2           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
  *  3           /usr/lib/jvm/jdk1.6.0_45/bin/java

  Enter to keep the current selection[+], or type selection number: 3


 [root@cdh ~]# update-alternatives --display java
 java - status is manual.
 link currently points to /usr/lib/jvm/jdk1.6.0_45/bin/java
 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java - priority 170019
 slave apt: (null)
 slave jar: (null)
 slave javac: (null)
 slave servertool.1.gz: /usr/lib/jvm/jdk1.6.0_45/man/man1/servertool.1.gz
 slave tnameserv.1.gz: /usr/lib/jvm/jdk1.6.0_45/man/man1/tnameserv.1.gz
 slave unpack200.1.gz: /usr/lib/jvm/jdk1.6.0_45/man/man1/unpack200.1.gz
 Current `best' version is /usr/lib/jvm/jdk1.6.0_45/bin/java.


 [root@cdh ~]# java -version
 java version "1.6.0_45"
 Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
 Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
comments powered by Disqus