Published January 16, 2018 by

Install Java 8 in CentOS/Redhat

Install Java in CentOS/Redhat

# cd /opt

# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.tar.gz"

# tar xzf jdk-8u161-linux-x64.tar.gz

After extracting java file use alternatives command to install it. alternatives command is available in chkconfig package.

# cd /opt/jdk1.8.0_161/
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_161/bin/java 2
# alternatives --config java


There is 1 program that provides 'java'.

  Selection    Command

-----------------------------------------------

*+ 1           /opt/jdk1.8.0_161/bin/java

Enter to keep the current selection[+], or type selection number: 1

Setup javac and jar commands path using alternatives:

# alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_161/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_161/bin/javac 2
# alternatives --set jar /opt/jdk1.8.0_161/bin/jar
# alternatives --set javac /opt/jdk1.8.0_161/bin/javac

Check Java Version

# java -version


Set Java Environment Variable

Setup JAVA_HOME, JRE_HOME and PATH environment variables

# export JAVA_HOME=/opt/jdk1.8.0_161
# export JRE_HOME=/opt/jdk1.8.0_161/jre

Also insert above environment variables in /etc/environment file.