Install Java On CentOS
You can install one or several Java packages on your machine. You can also
decide which version you want on your system by installing a specific version
number. The current default, Long-Term-Support (LTS) version is Java 11.
Install OpenJDK 11
1. Update the package repository to ensure you download the latest software:
sudo yum update
2. Then, install the Java Development Kit with the following command:
sudo yum install java-11-openjdk-devel
The output displays the downloaded and installed JDK, as in the image below:
Install OpenJRE 11
Java Runtime Environment 11 (Open JRE 11) is a subset of OpenJDK.
Therefore, both packages are included in the command:
sudo yum install java-11-openjdk
Install Oracle Java 11
1. The official Oracle JDK is not available for download from the local
repository. You have to download the .rpm package from the Java SE
Downloads page.
2. The latest release is Java SE 12. However, Oracle Java 11 is LTS,
meaning it is the latest stable version.
Locate Java SE 11.0.3 (LTS) on the webpage and click on DOWNLOAD.
3. After the download is complete, you can install the package with the
command:
sudo yum localinstall jre-VERSION-linux-x64.rpm
Verify Java is Installed on Your
System
The following command shows which Java release you have and confirms
installation was successful:
java –version
If Java was successfully downloaded and installed, the output details should
match the image below:
Install Specific Version of Java
You can also install any of the other versions of Java by changing the version
number in the command.
Install JDK 8
You may decide to use Open JDK 8, instead of the default OpenJDK 11.
To do so, type in the following command in the terminal:
sudo yum install java-1.8.0-openjdk-devel