Install Java on CentOS

As you cannot install Oracle’s (former Sun’s) JDK with the comfy CentOS package manger Yum, you’ll have to install Java manually. This article describes how to install Java 1.6 via command line on CentOS 5.5. Let’s go!

Before we log into CentOS, we need to get the JDK download link from Oracle’s website. Therefore, go to and click the button Download JDK:

On the next page, select from the Platform drop down list either Linux (if your CentOS runs on a 32bit system) or Linux x64 for a 64bit system. Then, click Continue:

Choose your Java distribution

On the next page copy the download link by right-clicking on jdk-6u23-linux-x64.bin and choose Copy Link Location from the browser’s context menu:

Copy Java download link

Now, please log into your CentOS system via command line. We will install Java to /usr/java. If you prefer a different location just change the path accordingly in the following commandos:

  1. Create the folder /usr/java:
    cd /usr
    mkdir java
  2. Change to the java directory and download Java from Oracle (paste the long download URL we copied earlier between quotes):
    cd java
    wget ""
  3. Actually, the long URL we copied earlier redirects to the very download URL. So wget saved the download to a file named
    So, let’s rename the bulky filename:
    mv jdk-6u23-linux-x64.bin?AuthParam=1295528165_cf13992779f41d08023a501f6b61f497&TicketId=B%2Fw2lh2ATV9LQRBDPlFTkAXl&GroupName=CDS&FilePath=%2FESD6%2FJSCDL%2Fjdk%2F6u23-b05%2Fjdk-6u23-linux-x64.bin&File=jdk-6u23-linux-x64.bin jdk-6u23-linux-x64.bin
  4. Make sure the file is executable:
    chmod +x jdk-6u23-linux-x64.bin
  5. Next run the installer:
    At the end of the installation just hit enter.
  6. Remove the installation package:
    rm -f jdk-6u23-linux-x64.bin
  7. Finally, we need to add a symbolic link to the Java executable:
    ln -s /usr/java/jdk1.6.0_23/bin/java /usr/bin/java
    I assumed you only want to have one version of Java installed. Just in case you already have another Java version installed and you want to be able to flexibly choose among those versions, you can establish the symbolic link with the alternatives command:
    alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_23/bin/java 2
    alternatives --config java
    Choose the Java version you want to have referenced.

That’s it! Type java -version on the command line and you should get a similar result to this:

java version "1.6.0_23"
Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
Java HotSpot(TM) 64-Bit Server VM (build 19.0-b09, mixed mode)

Finally, you might want to add the environment variable JAVA_HOME (which is needed by Apache Tomcat server, for example). To do so, simply type this command in your command line:

echo "export JAVA_HOME=/usr/java/jdk1.6.0_23" >> /etc/profile

This commando will write the JAVA_HOME environment variable to the file /etc/profile which contains system wide environment configuration.

Here you go. Enjoy running Java applications on your CentOS system!

This entry was posted in Dev and tagged , . Bookmark the permalink.

2 Responses to Install Java on CentOS

  1. devarpan says:

    Thank you.. it worked like a charm. Was never able to update my java version before !!!! Cheers.

  2. Omar Demello says:

    Thank you so much for this step-by-step guide. It did the trick, it’s just too bad I told everyone connected to my server it would take an hour and it only took a few minutes : ).

Comments are closed.