How to install Java in Centos 5 and 6
First you need to Download Archive File from oracle.
Download latest version of java from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Install JAVA using Alternatives
After extracting java archive file, you just need to set up to use newer version of java using alternatives using the follwoing commands.
# cd /usr/src/jdk1.7.0_65/
# alternatives –install /usr/bin/java java /opt/jdk1.7.0_65/bin/java 2
# alternatives –config java
There are 4 programs which provide ‘java’.
* 1 /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
+ 2 /opt/jdk1.7.0_55/bin/java
Enter to keep the current selection[+], or type selection number: 4 [Press Enter]
Now you may also required to setup javac and jar commands path using alternatives
# alternatives –install /usr/bin/jar jar /opt/jdk1.7.0_65/bin/jar 2
# alternatives –install /usr/bin/javac javac /opt/jdk1.7.0_65/bin/javac 2
# alternatives –set jar /opt/jdk1.7.0_65/bin/jar
# alternatives –set javac /opt/jdk1.7.0_65/bin/javac
Check JAVA Version
Use following command to check which version of java is currently being used by system.
# java -version
java version “1.7.0_65”
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) Client VM (build 24.60-b09, mixed mode)
Setup Environment Variables
Most of java based application’s uses environment variables to work. Use following commands to set up it.
Setup JAVA_HOME Variable
# export JAVA_HOME=/opt/jdk1.7.0_65
Setup JRE_HOME Variable
# export JRE_HOME=/opt/jdk1.7.0_65/jre
Setup PATH Variable
# export PATH=$PATH:/opt/jdk1.7.0_65/bin:/opt/jdk1.7.0_65/jre/bin
You can follow above steps to install multiple version of java as same time, but you can use only one version at a time.