update yum

$ sudo yum update

first make sure you have wget

$ sudo yum install wget


go to opt directory

$ cd /opt/

download latest version of java
see official page for latest version:

$ sudo wget –no-cookies –no-check-certificate –header “Cookie:; oraclelicense=accept-securebackup-cookie” “”

extract it, it will create the directory jdk1.8.0_101

$ sudo tar zxf jdk-8u101-linux-x64.tar.gz

let’s see if any alternative old java used

$ cd /etc/alternatives
$ ls -l java
java -> /usr/lib/jvm/java-1.7.0-openjdk-

if your java points to an old version i.e 1.7.x then follow this steps

$ sudo alternatives –install /usr/bin/java java /opt/jdk1.8.0_101/bin/java 2
$ sudo alternatives –config java

You will see a list of jdks, select the latest java number (I selected number 2 which is the /opt/jdk1.8.0_101/bin/java

Now JAVA 8 has been successfully installed on the system. It’s also recommend to setup javac and jar commands path using alternatives

$ sudo alternatives –install /usr/bin/jar jar /opt/jdk1.8.0_101/bin/jar 2
$ sudo alternatives –install /usr/bin/javac javac /opt/jdk1.8.0_101/bin/javac 2
$ sudo alternatives –set jar /opt/jdk1.8.0_101/bin/jar
$ sudo alternatives –set javac /opt/jdk1.8.0_101/bin/javac

check java verion

$ java -version
java version “1.8.0_101”
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode

configure java environmental variables


setup JAVA_HOME variable

$ export JAVA_HOME=/opt/jdk1.8.0_101/

setup JRE_HOME

$ export JRE_HOME=/opt/jdk1.8.0_101/jre/

setup PATH variable

$ export PATH=$PATH:/opt/jdk1.8.0_101/bin:/opt/jdk1.8.0_101/jre/bin

However, to make it persistent use the below method instead of above

become root

$ sudo su

go to bashrc

$ vi /etc/bashrc
export JAVA_HOME=/opt/jdk1.8.0_101/
export JRE_HOME=/opt/jdk1.8.0_101/jre/
export PATH=$PATH:/opt/jdk1.8.0_101/bin:/opt/jdk1.8.0_101/jre/bin

source it

$ source /etc/bashrc


One thought on “INSTALL JAVA 8 ON CENTOS 7

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s