Install Oracle Java on CentOS from CLI

1. Make sure the CentOS 6.4 system is fully up-to-date, with:

yum update

2. Once the update completes, check the system for any other installed Java packages using:

rpm -qa | grep -E '^open[jre|jdk]|j[re|dk]'

There was the java-1.6.0-openjdk-1.6.0.0-1.56.1.11.8.el6_3.i686 package already installed so I removed it with:

yum remove java-1.6.0-openjdk

3. Download the required Java JDK package. I'm running 64 bit CentOS 6.4 so I needed to get the 64 bit Java JDK package from Oracle's Java download page.

cd /usr/java/ (mkdir /usr/java if it doesn’t exist)
wget --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2Ftechnetwork%2Fjava%2Fjavase%2Fdownloads%2Fjdk6-downloads-1637591.html;" http://download.oracle.com/otn-pub/java/jdk/6u33-b03/jdk-6u33-linux-x64.bin
Note: You will need to change the version number to make this work moving forward.

4. Install the downloaded package, with:

./chmod 755 jdk-6u33-linux-x64.bin & ./jdk-6u33-linux-x64.bin 

5. Configure Java on the system using the alternatives command. This is in order to tell the system what are the default commands for Java. Most sys admins aren't aware about this and I think that it is a vital part when setting the Java package

a) Setting up the Java JDK6 package alternatives using:

alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_33/jre/bin/java 20000
alternatives --install /usr/bin/jar jar /usr/java/jdk1.6.0_33/bin/jar 20000
alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_33/bin/javac 20000
alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.6.0_33/jre/bin/javaws 20000
alternatives --set java /usr/java/jdk1.6.0_33/jre/bin/java
alternatives --set javaws /usr/java/jdk1.6.0_33/jre/bin/javaws
alternatives --set javac /usr/java/jdk1.6.0_33/bin/javac
alternatives --set jar /usr/java/jdk1.6.0_33/bin/jar

6. Verify the installed version of Java with:

java -version
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03, mixed mode)

7. Set Java global environment variables, with:

cd /etc/profile.d
vi /etc/profile.d/java.sh
Add to java.sh:
export JRE_HOME=/usr/java/jdk1.6.0_33/jreexport PATH=$PATH:$JRE_HOME/binexport JAVA_HOME=/usr/java/jdk1.6.0_33export JAVA_PATH=$JAVA_HOMEexport PATH=$PATH:$JAVA_HOME/bin 
Force the execution of java.sh (or you  can reboot), with:
source java.sh 


Comments

Popular posts from this blog

Authentication for RESTful APIs

Security From Happiness

How to build a simple RESTful API with Flask