You may find that sometimes you need to use the Sun Java 6 version of the JDK as opposed to version 7 on your Centos box. Some projects may require the older version, additionally there are still some potential security issues in version 7 which regularly render Oracle as reminiscent of the boy with his finger in the dam. Until these are properly fixed you may wish to use JDK6 instead of or at least alongside JDK7. Well this is easy enough to do on Centos 6/RHEL with a few commands.
First install jpackage-utils if not already installed
$ sudo yum -y install jpackage-utils
Now we have to download JDK6 from Oracle's Web site.
The latest version is 1.6.0_43 so download the bin version for Linux to your home directory. First change the permissions.
$ chmod +x jdk-6u43-linux-i586.bin (or x64)
Extract the bin file
Move extracted folder to its location, usually /usr/java
If you don't aready have a java version installed, then you might want to make a directory for it.
$ sudo mkdir /usr/java
$ sudo mv jdk1.6.0_43 /usr/java/jdk1.6.0_43
If you have already installed JDK7 then you will have a new folder next to it with version 6 inside, that is fine.
Install the new java 6 source in system
$ sudo update-alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_43/bin/javac 1
$ sudo update-alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_43/bin/java 1
$ sudo update-alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.6.0_43/bin/javaws 1
Choose default java from the versions you now have, repeat with javac and javaws.
$ sudo update-alternatives --config javac
$ sudo update-alternatives --config java
$ sudo update-alternatives --config javaws
* 2 /usr/java/jdk1.7.0_10/jre/bin/java
+ 3 /usr/java/jdk1.6.0_43/bin/java
Enter to keep the current selection[+], or type selection number:
Test which version you are now running
$ java -version
java version "1.6.0_43"
Java(TM) SE Runtime Environment (build 1.6.0_43-b01)
Java HotSpot(TM) Server VM (build 20.14-b01, mixed mode)
Verify the symlinks all point to the new java location
$ ls -la /etc/alternatives/java*
lrwxrwxrwx. 1 root root 30 Mar 17 12:47 /etc/alternatives/java -> /usr/java/jdk1.6.0_43/bin/java
lrwxrwxrwx. 1 root root 31 Mar 16 23:59 /etc/alternatives/javac -> /usr/java/jdk1.6.0-43/bin/javac
lrwxrwxrwx. 1 root root 32 Mar 16 23:59 /etc/alternatives/javaws -> /usr/java/jdk1.6.0_43/bin/javaws
Now set up the $JAVA_HOME path.
$ sudo vi/home/<user>/.bashrc
$ source /home/<user>/.bashrc
Enable Java plugin for Mozilla Firefox (and Chrome)
sudo alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/latest/jre/lib/i386/libnpjp2.so 20000
sudo alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/jdk1.7.0_06/jre/lib/amd64/libnpjp2.so 20000
You can now switch between JDK7 and JDK 6 using the update-alternatives command above.
Labels: Centos 6, Install Java JDK6, RHEL