How to install multiple Java versions on CentOS 8

Java is one of the most widely used high-level programming languages and was originally developed by Sun Microsystems.  It is used to create a complete application or systems that can run on a single computer system or in a distributed server environment. In addition, Java is also used to create a small application or applet that is part of the web page.

Java has two different implementations, OpenJDK and Java Oracle. Both are roughly the same and do not differ, except that Java Oracle provides additional functionality. OpenJDK is an open-source Java implementation platform. The Java Oracle is subject to licensing, which means that it may only be used for non-commercial purposes, e.g. for personal use and development.

In this article, we will learn how to install various Java implementations on CentOS 8.

Installation of Java on CentOS 8

To install java, you need to install the two different implementations of Java on your system. Perform the following step to install Java on CentOS 8:

  1. First, you need to log in as an admin or root user on your system.
  2. Open the terminal using the shortcut method ‘Ctrl+Alt+t’.

Install OpenJDK 11

It is a best practice to install the latest Java version of JDK 11. A few applications java-based may need java specific version, so in this situation, you need to read the application documentation first.

You will run the following command to install openJDK11on your system CentOS 8:

$ sudo dnf install java-11-openjdk-devel

Install OpenJDK Development Kit

During the installation, a user confirmation prompt to be displayed on the terminal. You will press ‘y’ and hit ‘Enter’ to allow the installation of Java packages on your system.

Confirm installation

You will see that the ‘complete’ status has been displayed for OpenJDK 11 installation on the terminal.

Installation completed

Check Java version

Once the installation is completed, now you can verify the java installation by displaying the installed java version. For this purpose, you need the command as follows:

$ java -version

Check the Java version

At that stage, Java has been successfully installed on your system CentOS 8.

You can also install the headless version of java on your CentOS 8 that supports minimal java runtime required for the application execution process without using GUI means no mouse, keyboard, and support of display systems. The headless version is better for server applications.

You need to type the following command to only install the headless OpenJDK 11 version on your system:

$ sudo dnf install java-11-openjdk-headless

Install Java Headless

If the above type is already installed on your CentOS 8 then headless package will install as a dependency.

Install OpenJDK 8

Similarly, you can install OpenJDK 8 on your system. The default repository of CentOS 8 contains the two major latest versions of Java LTS, Java 8, and 11. OpenJDK 8 is also a commonly used version. To install Java 8 you need to execute the following command:

$ sudo dnf install java-1.8.0-openjdk-devel

After completing the installation of Java 8, now you can verify it by checking version information as follows:

$ java -version

You can also install the headless version of Java 8.

Set Java default version

If multiple Java versions are installed on your CentOS 8, in this case, you can use the default version of Java. It means when you will type java on the terminal then which version will be used as default as follows:

$ java -version

If you want to change the above version with new alternatives you will the following command:

$ sudo alternatives --config java

Check Java Version

After running the above command, a list of installed java versions will be displayed on the terminal. Now, you will select the number which you want to set as default.


In this article, you have learned how you can install different versions of Java on CentOS 8. Moreover, you see how to set the default Java version if multiple versions installed on your system. In the next, you can explore more about the path setting of java. I hope you have enjoyed this article.