How to Install Java on RHEL 8 / CentOS 8 Linux

Java is incredibly popular on servers, and if you plan on using RHEL 8 / CentOS 8, you’ll need to install it. There are a couple of ways to install Java on RHEL, both from the open source OpenJDK packages and directly from Oracle.

In this tutorial you will learn:

  • How to Install OpenJDK 8
  • How to Install OpenJDK 11
  • How to Install Oracle Java 8 JRE
  • How to Install Oracle Java 8 JDK
  • How to Switch Java Versions

Java on RHEL 8

Java on RHEL 8.

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System RHEL 8 / CentOS 8
Software Java
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to Install OpenJDK 8

Install OpenJDK 8 on RHEL 8 / CentOS 8

Install OpenJDK 11 on RHEL 8 / CentOS 8.

OpenJDK 8 is available right in the default RHEL 8 / CentOS 8 repositories. If that’s the version of Java that you need, go ahead and install the package with DNF.



# dnf install java-1.8.0-openjdk-devel

How to Install OpenJDK 11

Install OpenJDK 11 on RHEL 8

Install OpenJDK 11 on RHEL 8 / CentOS 8.

OpenJDK 11 is a bit newer version of Java, but the Red Hat included it in RHEL 8 / CentOS 8 to “future proof” the release and cater to newer application that may arise in RHEL’s 10 year lifespan. If you’re looking for the latest from Java, install it with DNF.

# dnf install java-11-openjdk-devel

How to Install Oracle Java 8 JRE

There are always reasons to install the official version of Java straight from Oracle. Since Oracle Linux is essentially a clone of RHEL, there’s no problem getting Java this way too.

Download Oracle Java 8

Download Oracle Java 8.

Head over to Oracle’s Java download page, and download the latest 64bit RPM. It’s at the bottom of the link list.

Install Java 8 JRE on RHEL 8

Install Java 8 JRE on RHEL 8.

When you have your RPM, open a terminal, and use DNF to install the file locally.



# dnf install /home/user/Downloads/jre-8u201-linux-x64.rpm

How to Install Oracle Java 8 JDK

Download Oracle JDK 8

Download Oracle JDK 8.

If you’re looking to develop with Java, you’re going to need the JDK too. Oracle provides a package for that as well. Go to the Oracle JDK download page, and locate the Linux x64 RPM download under the first “Java SE Development Kit” heading. Be sure to accept the license agreement first.

Install Java 8 JDK on RHEL 8

Install Java 8 JDK on RHEL 8.

Once you have your RPM, use DNF to install it again, just like before with the JRE.

# dnf install /home/user/Downloads/jdk-8u201-linux-x64.rpm

How to Switch Java Versions

Check Java Version on RHEL 8

Check Java Version on RHEL 8.

You can have multiple versions of Java on the same system. In order to make full use of any one of them, you’ll need to be able to switch between releases easily, and you can using simple tools built in to RHEL. Begin by checking which version of Java you’re currently running.

$ java -version
Switch Java Version on RHEL 8

Switch Java Version on RHEL 8.



Now, you can use alternatives to list out the available versions of Java and enable the one you want to use.

# alternatives --config java

You’ll see a list of the available Java versions. Enter the number corresponding to the one you want to use, or press Enter to keep your current one.

Conclusion

You’re officially ready to start working with Java onRHEL 8 / CentOS 8. You don’t need to install all of these, and OpenJDK will probably be suitable for most applications. That said, it’s nice to have options, and RHEL 8 / CentOS 8 certainly provides enough of them.