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

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.

  1. sudo yum -y install java-11-openjdk java-11-openjdk-devel
  2. $ java -version
  3. openjdk version "11.0.12" 2021-07-20 LTS
  4. OpenJDK Runtime Environment 18.9 (build 11.0.12+7-LTS)
  5. OpenJDK 64-Bit Server VM 18.9 (build 11.0.12+7-LTS, mixed mode, sharing)
  6. $ which java
  7. /usr/bin/java

set Java environment variables

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

Source the file to start using it without logging out.

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

  1. wget --no-check-certificate -c --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/11.0.12%2B8/f411702ca7704a54a79ead0c2e0942a3/jdk-11.0.12_linux-x64_bin.rpm

Then install the package with the rpm command

  1. $ sudo rpm -Uvh jdk-11.0.12_linux-x64_bin.rpm
  2. warning: jdk-11.0.12_linux-x64_bin.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
  3. Verifying... ################################# [100%]
  4. Preparing... ################################# [100%]
  5. Updating / installing...
  6. 1:jdk-11.0.12-2000:11.0.12-ga ################################# [100%]

Confirm Java version installed

  1. [root@iZuf62l0oc6zyphfsga1nuZ data]# java --version
  2. java 11.0.12 2021-07-20 LTS
  3. Java(TM) SE Runtime Environment 18.9 (build 11.0.12+8-LTS-237)
  4. Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.12+8-LTS-237, mixed mode)