Saturday, May 14, 2011

How to install Sun Java 1.6 onto CentOS 5.5


In this step-by-step walkthrough, you will install Sun Java JRE 1.6.0_25 onto CentOS 5.5.  CentOS comes available with openJDK, an open source Java version.  Some applications (such as JIRA) may not be fully compatible with this version and require the standard Sun JRE or JDK to function properly. Sun Java is not available via YUM.  Installing Sun Java on CentOS is simple, but there are some wrinkles that, if not properly addressed, will cause some needless troubleshooting.  These steps are not fully discussed by the Sun Java installation instructions.


Download the Linux binary (not the rpm.bin version).

Create a new directory:

mkdir /opt/java

Copy the binary into this new directory

Change the permissions of the binary:

chmod 755 /opt/java/jre-6u25-linux-i586.bin

Launch the binary:


NOTE: you will not experience a license prompt while this is executing - this is a variation from the Sun Java instructions for this.

Verify that the java directory was created:

ls -l /opt/java

You should see this:


Change java directory permissions to allow all user access:

chmod 755 /opt/java

Create a new global environment variable for Java with system-wide access:

gedit /etc/profile.d/

or use

vi /etc/profile.d/
Add the following lines to this file:

export JRE_HOME=/opt/java/jre1.6.0_25
export PATH=$PATH:$JRE_HOME/bin

export JAVA_HOME=/opt/java/jre1.6.0_25

export PATH=$PATH:$JAVA_HOME/bin

Save and exit.

Verify that the new file has been created:

ls -l /etc/profile.d

One of the items listed should be the following:

Load this new global environment variable:

source /etc/profile.d/

Verify that the new environment variables are active:


This should return (for this procedure):


Repeat this process for the other global environment variables you created.

Or check for all Java environment variables:

env or printenv

Configure alternatives:

alternatives --install /usr/bin/java java /opt/java/jre1.6.0_25/bin/java 2

Now select which Java is default:

alternatives --config java

This returns

  Selection    Command
+ 1           /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
   2           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
   3           /opt/java/jre1.6.0_25/bin/java

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

Select 3, or which ever number is associated with the version just installed.

Verify configuration:

java -version

This will return:

java version "1.6.0_25"
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) Client VM (build 20.0-b11, mixed mode, sharing)

This completes this procedure on Sun Java installation to CentOS 5.5.

  • None

1 comment:

Unknown said...

Hurray! First tutorial to work for me. Thanks so much.