All You Need to Know About Installing Java 11 or 12 on CentOS

Photo of author

By admin

Needless to specify that Java has retained its supremacy as a powerful, and multi-performing programming language and platform. The best thing about Java is that it is suitable for all patterns of programming. Naturally, Java is loved and preferred by the majority of developers and programmers.

As mentioned above, you’re free to install Java on any platform as it is platform-independent. There is nothing better than installing Java on CentOS to perform programming tasks.

However, installing Java on CentOS is not easy. Besides collecting information about the installation process, you are supposed to get details of the prerequisites too. Otherwise, the process will become harder for you and technical glitches might occur frequently. This article will provide an insight into the installation process of Java 11 and 12 on CentOS. So, let’s jump to the next segments of this article.

Why Install Java 11 and 12 Instead of Other Java Versions?

Before moving to the installation procedure, you must have adequate knowledge about different Java versions. If you’re a professional developer or programmer, you don’t need an introduction to different Java versions. However, if you’re a beginner who is just trying to run Java on CentOS, this section is important for you.

At present, four different Java editions are available – Java Standard Edition (Java SE), Java Enterprise Edition (Java EE), Java Micro Edition (Java ME), and Java FX. We need to look into the packages of Java Standard Edition of Java SE to learn the process of installing Java on CentOS. Currently, two main types of open-source Java packages are accessible for users. The first one is Java Runtime Environment or JRE while the other one is Java Development Kit or JDK.

Now, the confusing part is which one among these you should choose. It depends on your purpose for installing Java. JRE is good enough for running basic applications and programs of Java. But if you aim for developing or programming with Java, JDK should be your choice.

However, we suggest you go for the current LTS Java version, OpenJDK 11 to avoid confusion. Most users can’t figure out which version and implementation of Java they need. OpenJDK 11 is a one-stop solution for all of them.

How to Install Java 11 and 12 on CentOS?


  • Firstly, you need a valid user account on a CentOS machine, privileged with sudo benefits.
  • Make sure that you have access to the command line/terminal window.
  • The yum package manager, which is available by default on CentOS.

It’s possible to install more than one Java package on your system simultaneously. Now, let’s look into the main process.

Installation of OpenJDK 11

No need to mention that the latest software is the ideal one to download. So, don’t forget to update the package repository before you start the installation process. Use the following command to do so.

sudo yum update

Now, it’s time to install the Java Development Kit. You can do that easily by using the following command.

sudo yum install java-11-openjdk-devel

Check whether your screen is showing the following output or not. If not, start over the process once again.

[root@CentOS-7 ~]# sudo yum install java-11-openjdk-devel

Loaded plugins: fastestmirror, langpacks

Loading mirror speeds from cached hostfile

* base:

* extras:

* updates:

Resolving Dependencies

–> Running transaction check

—> Package java-11-openjdk-devel.x86_64 1: will be installed

–> Processing Dependency: java-11-openjdk(x86-64) = 1: for package: 1:java-11-openjdk-devel-

–> Running transaction check

—> Package java-11-openjdk.x86_64 1: will be installed

–> Processing Dependency: java-11-openjdk-headless(x86-64) = 1: for package: 1:java-11-openjdk-

–> Running transaction check

—> Package java-11-openjdk-headless.x86_64 1: will be installed

–> Finished Dependency Resolution

Dependencies Resolved


Package Arch Version Repository Size



java-11-openjdk-devel x86_64 1: updates 3.3 M

Installing for dependencies:

java-11-openjdk x86_64 1: updates 217 k

java-11-openjdk-headless x86_64 1: updates 39 M

Transaction Summary


Install 1 Package (+2 Dependent packages)

Total download size: 42 M

Installed size: 170 M

Is this ok [y/d/N]: y

Downloading packages:

warning: /var/cache/yum/x86_64/7/updates/packages/java-11-openjdk- Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY

Public key for java-11-openjdk- is not installed

(1/3): java-11-openjdk- | 217 kB 00:00:03

(2/3): java-11-openjdk-devel- | 3.3 MB 00:00:21

(3/3): java-11-openjdk-headless- | 39 MB 00:01:09


Total 620 kB/s | 42 MB 00:01:10

Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Importing GPG key 0xF4A80EB5:

Userid : “CentOS-7 Key (CentOS 7 Official Signing Key) <>”

Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5

Package : centos-release-7-7.1908.0.el7.centos.x86_64 (@anaconda)

From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Is this ok [y/N]: y

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

Installing : 1:java-11-openjdk-headless- 1/3

Installing : 1:java-11-openjdk- 2/3

Installing : 1:java-11-openjdk-devel- 3/3

Verifying : 1:java-11-openjdk-devel- 1/3

Verifying : 1:java-11-openjdk-headless- 2/3

Verifying : 1:java-11-openjdk- 3/3


java-11-openjdk-devel.x86_64 1:

Dependency Installed:

java-11-openjdk.x86_64 1: java-11-openjdk-headless.x86_64 1:


[root@CentOS-7 ~]#

Installation of OpenJRE 11

As OpenJRE is nothing but a subset of OpenJDK, both the packages can be installed by using the following command:

sudo yum install java-11-openjdk

Installation of Oracle Java 11

Now, you have to download the .rpm package of Oracle JDK from the official download page of Java SE. As you download the package, use the following command to install that on CentOS 7.

sudo yum localinstall jre-VERSION-linux-x64.rpm

Installation verification

It’s important to verify whether Java got installed in your system properly or not. To do so, you need to input the following command:

$ java -version

If the installation package has been successful, expect to see something similar to the following output:

[root@CentOS-7 ~]# java -version

openjdk version “11.0.7” 2020-04-14 LTS

OpenJDK Runtime Environment 18.9 (build 11.0.7+10-LTS)

OpenJDK 64-Bit Server VM 18.9 (build 11.0.7+10-LTS, mixed mode, sharing)

[root@CentOS-7 ~]#

Installation of Oracle Java 12

If you wish to install Java 12 on CentOS, follow the same procedure you executed for installing Java 11. However, before initiating the installation procedure, ensure that you have downloaded the right Java 12 package. The rest is the same as you have done already for Oracle Java 11.

That’s all you need to know about installing Java 11 and 12 on CentOS. As you have seen, the process is quite straightforward. Anyone with basic technical knowledge can install Java 11 or 12 on their CentOS system.

Upgrading Java 8 to Java 11 or 12 in CentOS

Did you have Java 8 installed in your system? Well, you can update Java 8 to Java 11 or 12 easily by following the steps mentioned below:

  • Firstly, follow the procedure mentioned above to install Java 11 in your system. As we have already mentioned, multiple Java versions can be installed on a system.
  • Now, use this command to set your preferred Java version as the default one on CentOS:

sudo alternatives –config java

  • Now, the output of the command will prompt you to enter the Java version number that you prefer. Suppose you want to set Java 12 as default, then you should enter 12. That’s all you need to do for setting your preferred version as default. Check out the following output to see whether you’re doing it right or not.

[root@CentOS-7 ~]# sudo alternatives –config java

There are 3 programs which provide ‘java’.

Selection Command


1 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-


*+ 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-


3 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-

Enter to keep the current selection[+], or type selection number: 3

[root@CentOS-7 ~]#

  • We have already mentioned the command earlier that allows you to verify the Java version of your system. Run the same command to check if you’ve successfully set your preferred Java version as default or not.

Procedure to Set JAVA_HOME Environment Variable

You must be curious about the necessity of the JAVA_HOME Environment Variable. Well, Java is a compilation of numerous applications. Those applications can access the installation path of Java with the help of the JAVA_HOME Environment Variable. Execute the following steps to set the JAVA_HOME Environment Variable:

Your first task is to locate where Java has been installed on your system. Use the following command for that:

sudo update-alternatives –config java

The output will show the path of each Java package that you have installed on your system. The path of a Java package looks like this:

/usr/lib/jvm/java-11-openjdk- (where OpenJDK 11 is located)

You need to copy the path of your preferred Java version. Now, use a text editor to open the .bash_profile.

Once the file gets opened, you have to add a line at the bottom of the file. That line should specify the location of JAVA_HOME. Look at the following format as an example:


Uninstalling a Java package on CentOS

You may want to uninstall a Java package on your CentOS system. Many CentOS users think of doing so because they don’t want to keep multiple Java packages.

The yum remove command is highly favorable for removing java from CentOS. Look at the following example to have a better idea of the yum remove command”

sudo yum remove java-1.8.0-openjdk-devel

You’re supposed to replace the OpenJDK version with the version you want to uninstall. After you input this command, you have to press y to confirm the uninstallation. Once the process ends, you can expect to see some output on the terminal like this:

If you don’t see this output, it means the uninstallation is not successful. In such a case, you need to start the uninstallation process again.

How Beneficial is it to Install Java on CentOS?

It’s really exciting to install a powerful language like Java on CentOS. Every programmer is familiar with the versatility and flexibility of Java as a programming language or platform. As you install Java on your CentOS system, you unleash unlimited opportunities.

The simplicity of Java will help you explore CentOS and its features and possibilities in better ways. Undoubtedly, that seems attractive from a passionate programmer’s perspective. Even if you’re not a developer or programmer, CentOS is still a decent option for you, and installing Java on CentOS will enhance your user experience. So, focus on the procedures mentioned above to learn different aspects of installing Java on CentOS.


From choosing a favorable Java package to installing it, we mentioned every detail in the above sections. Also, the article highlighted the procedure for setting up the JAVA_HOME environment variable along with the process of upgrading from Java 8 to Java 11 or 12 and explained a simple way to uninstall Java packages on CentOS. So, you likely have developed complete knowledge of everything associated with the Java installation process. Now, it’s time to make your knowledge work. Just follow the instructions properly and install Java 11 or 12 on your CentOS system.

Leave a Comment