Install Java 11 (OpenJDK 11) on RHEL 8|CentOS 8|Rocky Linux 8

There are two ways of installing Java 11 on RHEL 8 / CentOS 8 / Rocky Linux 8.

  1. Install Java SE Development Kit 11 (JDK 11)
  2. Install OpenJDK 11

It is recommended to install OpenJDK 11 because of the license issues around Java SE Development Kit. This guide will cover the installation of both.

For Ubuntu use: How to Install Java 11 on Ubuntu

Install OpenJDK 11 on RHEL 8|CentOS 8|Rocky Linux 8

OpenJDK is a free and open-source implementation of the Java Platform, Standard Edition licensed under the GNU General Public License version 2.

sudo yum -y install java-11-openjdk java-11-openjdk-devel

Once OpenJDK 11 is installed, confirm it works by checking the version.

$ java -version
openjdk version "11.0.14" 2022-01-18 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.14+9-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.14+9-LTS, mixed mode, sharing)

$ which java
/usr/bin/java

Set Java environment variables

sudo tee /etc/profile.d/java11.sh <<EOF
export JAVA_HOME=\$(dirname \$(dirname \$(readlink \$(readlink \$(which javac)))))
export PATH=\$PATH:\$JAVA_HOME/bin
export CLASSPATH=.:\$JAVA_HOME/jre/lib:\$JAVA_HOME/lib:\$JAVA_HOME/lib/tools.jar
EOF

Source the file to start using it without logging out.

source /etc/profile.d/java11.sh

Install Java SE Development Kit 11 (JDK 11) on RHEL 8 / CentOS 8 / Rocky Linux 8

Download the latest release of JDK 11.

$ file jdk-11.0.15.1_linux-x64_bin.rpm
jdk-11.0.15.1_linux-x64_bin.rpm: RPM v3.0 bin i386/x86_64 jdk-11-2000:11.0.15.1-ga

If you have other versions of JDK installed, you set your default Java as follows.

sudo alternatives --list
sudo alternatives --config java

Select Java version to use as default.

install java 11 rhel 8 select java

This will switch the system java binary to selected Java. Also do the same for  javac since java and javac are independently managed.

sudo alternatives --config javac

Leave a Reply

Your email address will not be published. Required fields are marked *