How can I install Java 8 on CentOS 8 / RHEL 8?. On Red Hat Enterprise Linux (RHEL) 8, two major versions of Java are available – Java 11 and Java 8. Our last article addressed the installation of Java 11 on CentOS / RHEL 8. In this article, I’ll cover the installation of Java 8, specifically, JDK (Java Development Kit) 8 on RHEL / CentOS 8.

You can check features of RHEL 8 and optionally how to install RHEL 8 if you’re a new user.

Install Java 8 on CentOS 8 / RHEL 8

To install JDK 8 on your CentOS 8 / RHEL 8 server or workstation machine, Use the following command.

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

Check version to validate installation of Java 8 on CentOS 8 / RHEL 8.

$ java -version
openjdk version "1.8.0_201"
OpenJDK Runtime Environment (build 1.8.0_201-b09)
OpenJDK 64-Bit Server VM (build 25.201-b09, mixed mode)

 Set Java environment variables.

cat <<EOF | sudo tee /etc/profile.d/
export JAVA_HOME=/usr/lib/jvm/jre-openjdk
export PATH=\$PATH:\$JAVA_HOME/bin
export CLASSPATH=.:\$JAVA_HOME/jre/lib:\$JAVA_HOME/lib:\$JAVA_HOME/lib/tools.jar

Activate Java environment.

source /etc/profile.d/

Create a simple Java application to see Java 8 working on RHEL / CentOS 8.

cat > <<EOF
public class HelloWorld {
	public static void main(String args[]) {
		System.out.println("Hello World");

Compile your Java source code.

$ javac

This will create HelloWorld.class file, which is the bytecode embodiment of the source code. To run the HelloWorld.class file, use:

$ java HelloWorld
Hello World

You now have Java installed and configured on RHEL 8 / CentOS 8. Enjoy your development!!.

Video courses:

Want to Master Java Programming language, check:

Best Books for Learning Java Programming

For Java 11, use how to install Java 11 on RHEL / CentOS 8.

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here