Install and Upgrade Java Version on CentOs ,Red Hat and Fedora Linux
When the server OS installed on server or system, most of the time java version is not updated and also some time we need to update or upgrade java version on server. Earlier in our article we have install Java version 8 update 51 on fresh installed server . Now we are going to upgrade or update Java version from java version 1.8 update 51(1.8.0_51) to Java version 1.8 update 111 (1.8.0_111) . Here you can see also the multiple version of java also installed on server. Recently Java version 1.8 update 111 launched.
Below is my java version , I ran the command to check java version java -version, Now here is output of my command.
[[email protected]]# java -version java version "1.8.0_51" Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Below are the steps to installed or upgrade java version .
Downloading Latest Java Version
Here was java launch recently update 60 , so we have download 1.8.0_60 on the server through below command . You can find latest version of java on official site page.
Run below command to download and extract the downloaded file .
For Linux x64 ( 64 Bit )
# cd /tmp
# curl -LO http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.tar.gz -H --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"
# tar xzf jdk-8u111-linux-x64.tar.gz
# mv jdk1.8.0_111 /opt
For Linux x86 ( 32 Bit )
# curl -LO http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-i586.tar.gz -H --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"
#tar xzf jdk-8u111-linux-i586.tar.gz
# mv jdk1.8.0_111 /opt
As we have earlier discussed in other articles that –no-cookies and –header option with curl or wget because of oracle does not give download unless we have not accept their license or terms .for accept header and license use above syntax for download .
Upgrade or Install Java
Now go to the java extracted folder through below command and install or switch to java version through alternatives command. This is the best way to install or switch java version to other. When we run the alternatives –config java , the command output will show different java programs which provide java, We need to choose or select command.Here we have selected /opt/jdk1.8.0_60/bin/java .Follow below command to set up.
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_111/bin/java 2
# alternatives --config java
There are 3 programs which provide 'java'. Selection Command ----------------------------------------------- * 1 /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java + 2 /opt/jdk1.8.0_51/bin/java 3 /opt/jdk1.8.0_111/bin/java Enter to keep the current selection[+], or type selection number: 3
Now set the jar and javac path .
[[email protected] jdk1.8.0_111]# alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_111/bin/jar 2
[[email protected] jdk1.8.0_111]# alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_111/bin/javac 2
[[email protected] jdk1.8.0_111]# alternatives --set jar /opt/jdk1.8.0_111/bin/jar
[[email protected] jdk1.8.0_111] # alternatives --set javac /opt/jdk1.8.0_111/bin/javac
Now set the Environment Variables path of Java,Jre home variable through below commands
# export JAVA_HOME=/opt/jdk1.8.0_111
# export JRE_HOME=/opt/jdk1.8.0_111/jre/
Check updated Java Version :
[[email protected] jdk1.8.0_111]# java -version
Java(TM) SE Runtime Environment (build 1.8.0_111-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode) Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)