How to install multiple versions of Java on CentOS 8

s2 0

Java is one of the most widely used high-level programming languages ​​and was originally developed by Sun Microsystems. It is used to build 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 website.

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

This article shows you 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. Follow the step below to install Java on CentOS 8:

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

Install OpenJDK 11

We recommend that you install the latest Java version of JDK 11. Some Java-based applications may require a Java-specific version, so in this situation you will need to read the application documentation first.

You run the following command to install openJDK11 on your CentOS 8 system:

$ sudo dnf install java-11-openjdk-devel

A user confirmation prompt is displayed on the terminal during the installation. You press ‘y’ and press ‘Enter’ to allow Java packages to be installed on your system.

You will see that the status of the OpenJDK 11 installation on the terminal was ‘complete’.

installation completed

Check Java version

Once the installation is complete, you can now verify the Java installation by viewing the installed Java version. To do this, you need the command as follows:

$ java -version

Check the Java version

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

You can also install the headless version of Java on your CentOS 8, which supports the minimum Java runtime required for the application execution process without using the GUI, i.e. no mouse, keyboard, and display systems support. The headless version is better suited for server applications.

You need to enter the following command just to 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, the headless package will be installed as a dependency.

Install OpenJDK 8

You can also install OpenJDK 8 on your system. CentOS 8’s standard repository 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 run the following command:

$ sudo dnf install java-1.8.0-openjdk-devel

Now that you have finished installing Java 8, 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 the default Java version

If you have multiple versions of Java installed on your CentOS 8, you can use the standard version of Java in this case. This means when you enter Java on the terminal, which version will be used as the default, as follows:

$ java -version

If you want to change the above version with new alternatives, run 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 select the number that you want to set as the default.

diploma

In this article, you learned how to install different versions of Java on CentOS 8. It also tells you how to set the default Java version if you have multiple versions installed on your system. In the next section you will learn more about the path setting of java. Hope you enjoyed this article.

How to install multiple versions of Java on CentOS 8