(Last Updated On: January 2, 2019)

This article will help you to install Oracle Java 11 on RHEL 8. Java 11 is a long-term support (LTS) release which was made available to the General public on 25 September 2018 and is production-ready.

There are two ways of installing Java 11 on RHEL 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 18.04/16.04 & Debian 9, use: How to Install Java 11 on Ubuntu 18.04 /16.04 / Debian 9

For CentOS 7: How to Install Java 11 on CentOS 7 / Fedora 29 / Fedora 28

Install OpenJDK 11 on RHEL 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 install java-11-openjdk-devel
$ java -version
openjdk 11-ea 2018-09-25
OpenJDK Runtime Environment (build 11-ea+28)
OpenJDK 64-Bit Server VM (build 11-ea+28, mixed mode, sharing)
$ which java
/usr/bin/java

 set Java environment variables

cat > /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

Download the latest release of JDK 11.

curl -LO -H "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/11.0.1+13/90cf5d8f270a4347a95050320eef3fb7/jdk-11.0.1_linux-x64_bin.rpm"

Then install the package with the rpmcommand

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

Confirm Java version installed

$ java -version 
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

Write a Hello World Java code to test.

 cat > hello_world.java <<EOF
public class helloworld {
  public static void main(String[] args) {
    System.out.println("Hello Java World!");
  }
}
EOF

Run the code.

$ java hello_world.java
Hello Java World!

Selecting Java Versions with Alternatives

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.

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

You now have Java 11 installed on your RHEL 8 server. Enjoy coding in Java.