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:; oraclelicense=accept-securebackup-cookie" ""

# 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.