Installing Alternative Java Versions on RHEL/CentOS
Below is shorthand for installing alternative versions of Java on your RHEL/CentOS system. This may come in useful for the purposes of testing.
# Set version, update, and filename v="jdk1.8.0_101" r="8u101-b13" f="jdk-8u101-linux-x64.tar.gz" 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/${r}/${f}" tar xzf ${f} && /bin/rm -f ${f} cd /opt/${v} alternatives --install /usr/bin/java java /opt/${v}/bin/java 2 alternatives --install /usr/bin/jar jar /opt/${v}/bin/jar 2 alternatives --install /usr/bin/javac javac /opt/${v}/bin/javac 2 alternatives --set jar /opt/${v}/bin/jar alternatives --set javac /opt/${v}/bin/javac export JAVA_HOME=/opt/${v} export JRE_HOME=/opt/${v}/jre export PATH=$PATH:/opt/${v}/bin:/opt/${v}/jre/bin cat >> /etc/environment << EOF JAVA_HOME=/opt/${v} JRE_HOME=/opt/${v}/jre PATH=$PATH:/opt/${v}/bin:/opt/${v}/jre/bin EOF
Interactive step – select default Java version and verify
alternatives --config java java -version