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 http://www.oracle.com/technetwork/java/javase/downloads/index.html 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:
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:
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:
- Create the folder /usr/java:
cd /usr
mkdir java
- Change to the java directory and download Java from Oracle (paste the long download URL we copied earlier between quotes):
cd java
wget "http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jdk-6u23-linux-x64.bin?BundledLineItemUUID=phqJ_hCyWd8AAAEtmUBKPKN3&OrderID=SauJ_hCyzLMAAAEtjUBKPKN3&ProductID=6gGJ_hCwIQYAAAEsKIMcKluK&FileName=/jdk-6u23-linux-x64.bin"
- Actually, the long URL we copied earlier redirects to the very download URL. So
wget
saved the download to a file named
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
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 - Make sure the file is executable:
chmod +x jdk-6u23-linux-x64.bin
- Next run the installer:
./jdk-6u23-linux-x64.bin
At the end of the installation just hit enter. - Remove the installation package:
rm -f jdk-6u23-linux-x64.bin
- 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 thealternatives
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!
Thank you.. it worked like a charm. Was never able to update my java version before !!!! Cheers.
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 : ).