How to Install Java on CentOS 8

Install Java on CentOS 8

In this article, we will have explained the necessary steps to install and configure Java on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Java is one of the most popular programming languages used to build different kinds of applications and systems. Applications developed in Java are scalable, flexible and maintainable. Over 3 billion devices run on Java.

Install Java on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

Step 2. Install Java on CentOS.

To install the OpenJDK 11 on CentOS 8, run the following command:

Confirm the installation and check the version typing following command:

Step 3. Setting up default Java Version.

If you want to change the default version, use the alternatives command:

Setting the JAVA_HOME Environment Variable:

  • To set the JAVA_HOME variable on a per-user basis add it to the ~/.bashrc or any other configuration file which is loaded when the user logs in. For system-wide setting, use a script inside the /etc/profile.d directory:

Add the following line to the end of file:

For changes to take effect on your current shell, you can either log out and log in or use the source command:

Now verify JAVA_HOME path typing:

Congratulation, you have learned how to install and configure Java on CentOS 8. If you have any question, please leave a comment below.