How to install multiple versions of Java 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 a web page.

Java has two different implementations, OpenJDK and Java Java. Both of them are approximately the same and do not differ, except that Java Oracle provides additional functionality. OpenJDK is an open source Java implementation platform. Java Oracle is licensed, which means that it can only be used for non-commercial purposes, for example for personal use and development.

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

Install Java on CentOS 8

To install Java, you need to install two different Java implementations on your system. Follow the next step to install Java on CentOS 8:

  1. First, you need to log in as an administrator or as the root user on your system.
  2. Open the terminal using the keyboard shortcut “Ctrl + Alt + t”.

Install OpenJDK 11

It is recommended that you install the latest version of Java JDK 11. Some java-based applications may require a special version of java, so in this situation you must first read the application documentation.

To install openJDK11 on your CentOS 8 system, run the following command:

$ sudo dnf install java-11-openjdk-devel

During installation, the terminal displays a confirmation message from the user. You press “y” and press “Enter” to enable the installation of Java packages on your system.

Confirm Installation

You will see that to complete the installation of OpenJDK 11, the terminal displays the status “completed”.

Installation completed

Check Java Version

After installation is complete, you can now verify your Java installation by displaying the installed version of Java. To do this, you need the following command:

$ java -version

Check Java Version

At this point, Java was successfully installed on your CentOS 8 system.

You can also install the headless version of Java on CentOS 8, which supports the minimum Java runtime required to run the application without using a graphical interface, which means there is no mouse, keyboard, or display system support. The headless version is better for server applications.

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

$ sudo dnf install java-11-openjdk-headless

Install Java without a head

If the above type is already installed on your CentOS 8, then a package without a header will be installed as a dependency.

Install OpenJDK 8

In the same way, you can install OpenJDK 8 on your system. The standard CentOS 8 repository contains the two major recent versions of Java LTS, Java 8 and 11. OpenJDK 8 is also a widely used version. To install Java 8, you need to run the following command:

$ sudo dnf install java-1.8.0-openjdk-devel

After the Java 8 installation is complete, you can now verify this by checking the version information as follows:

$ java -version

You can also install the headless version of Java 8.

Set default Java version

If CentOS 8 has multiple versions of Java installed, then you can use the default version of Java. This means that when you type java on the terminal, which version will be used by default as follows:

$ java -version

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

$ sudo alternatives --config java

Check Java Version

After executing the above command, a list of installed versions of Java will be displayed on the terminal. Now you will select the number you want to set by default.

Conclusion

In this article, you learned how to install different versions of Java on CentOS 8. In addition, you will learn how to install the default version of Java if you have multiple versions installed on your system. Further you can learn more about configuring the Java path. I hope you enjoyed this article.

How to install multiple versions of Java on CentOS 8

Sidebar