How to Install Java on CentOS 8

Channel: Linux
Abstract: This tutorial will help to install Java on CentOS 8 and RHEL 8. Let’s follow the below simple steps for the installation. The Oracle Java 8 and Java 1

This tutorial will help to install Java on CentOS 8 and RHEL 8. Let’s follow the below simple steps for the installation. The Oracle Java 8 and Java 11 required subscription to download and install. So we use OpenJDK for this installation to run Java on CentOS 8 and RHEL 8 Linux system.

Step 1 – Search Java Packages

The OpenJDK rpm packages are available under the AppStream repository. Use the following command to search available Java packages under configured DNF repositories.

sudo dnf search openjdk
Step 2 – Install Java on CentOS 8

Now, use one of the following commands to install the required Java version on your CentOS 8 and RHEL 8 Linux system. You can also install the both Java version on any system and use as per your requirements.

Install JAVA 11:

sudo dnf install java-11-openjdk

Install JAVA 8:

sudo dnf install java-1.8.0-openjdk
Step 3 – Check Java Version

I have installed both Java version for this article, First I have installed Java 11 then installed Java 8 on my CentOS 8 system. Let’s check the installed and current active Java version on your system using the following command:

java -version

openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
Step 4 – Switch Between Java Versions

You can use alternatives command to switch between multiple Java versions installed on your CentOS 8 and RHEL 8 Linux systems.

sudo alternatives --config java

A list of installed Java versions will be displayed. Select the appropriate Java version number and press enter. In my case, Java 8 is currently active so I entered 1 in selection to change it to Java 11.

After change again check the current active Java version.

java -version

openjdk version "11.0.4" 2019-07-16 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.4+11-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.4+11-LTS, mixed mode, sharing)
Conclusion

In this tutorial, you have learned about installation of Java 11 and Java 8 on CentOS 8 Linux system.

Ref From: tecadmin

Related articles