Sun / Oracle Java JRE and CentOS 5.5 —

**I made a slight edit to this to help when a newer version of java is released.**

I’m a Debian guy, used to be a Red Hat Guy.. and was a Fedora guy for a long time too.. In Ubuntu and Mint it’s very very easy to install Java, but in RHEL and CentOS this is apparently not the case, I looked into it for my good friend Dave Simon.

My Test Setup:
I started with a Clean install of CENTOS 5.5 on a Virtual Machine under Virtual Box, I didn’t enable SELINUX because his machine doesn’t face the Vile and Dangerous Interwebs, and I turned off the Firewall for the same reason.

I also edited the sudoers file to grant myself Sudo access (CentOS doesn’t do this by default, which i think is wise) and then updated the system with: sudo yum update, and 323 mb of packages later I had an up to date system running in a VM.

By Default I see that the OpenJdk is installed, this is not the same as Sun’s Java JRE and isn’t compatible with many programs but it does satisfy the license requirements of distros like CentOS. So.. on to the Oracle / Sun Java!

So.. Step One: Download the Java JDK.(you can probably do this with just the JRE, but the JDK covers all your bases and WHY go thru the pain more than once right??)

The Current file name you end up with will be named jdk-6u21-linux-i586.bin

Open a console as root (you can type ‘su root’ and put in your root pwd.)
chmod a+x jdk-6u21-linux-i586.bin
to make the file exectuable. Then you need to run the file.
./jdk-6u21-linux-i586.bin this will extract all the files to a folder named “jdk1.6.0_21” in the same directory.. you then (as root) need to rename and then move this directory.
mv jdk1.6.0_21 java
mv java /usr/
You now are ready to tell a program that CentOS has called “Alternatives” to use this Sun Java and not the Open Java.

in the same console window (as root of course) you will type
cd /usr/sbin/
This gets you in the proper directory for alternatives, it’s not in a path so you have to be there to run these commands.
This is for the Java JRE
./alternatives --install /usr/bin/java java /usr/java/jre/bin/java 20000
This is for the Java Web Start
./alternatives --install /usr/bin/javaws javaws /usr/java/jre/bin/javaws 20000
This is for the Firefox Plugin for JRE
./alternatives --install /usr/lib/mozilla/plugins/ /usr/java/jre/lib/i386/ 20000
I think this is the Java C compliler (i dunno I don’t program in Java 😀 )
./alternatives --install /usr/bin/javac javac /usr/java/bin/javac 20000

You may now confirm your java version by typing
java -version

And in Firefox if you restat the browser you can check it’s plugins by first going to about:plugins in the address bar and then if you really wanna be sure head over to and click the “Do I have java” link.

To Upgrade your Java:

You just need to download the latest JDK and then mv it into the /usr/java/ folder. Please try not to have any java processes running as it probably won’t be appreciated 😀


Categorised as: Geeking Out


  1. Dave says:

    I wish I could geekliketodd… but alas I can only follow directions. Directions which are well written and give me some hot java action…

    Thanks Dude.

  2. […] tutorial was made on a real machine.. my “beater” and not a VM like my previous Java […]

  3. red says:

    what if the downloaded file is .rpm? what should i do then?

    • Itahh says:

      I had the same issue. It was a simple miatkse. If you are copying the entire line (like I did) Then you will have a space at the start of the command line. This space needs to be removed for it to work correctly. This is due to Linux sensitivity.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.