How To Install Java on Rocky Linux 8

Install Java on Rocky Linux 8

In this article, we will have explained the necessary steps to install Java on Rocky Linux 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 the most popular programming language used to build many applications, systems, and high-level object-oriented programming language. Java runs on all major operating systems and devices.

Installing Java on Rocky Linux 8

Step 1. First, before you start installing any package on your Rocky Linux server, we always recommend making sure that all system packages are updated.

sudo dnf update
sudo dnf upgrade
sudo dnf install wget curl

Step 2. Install Java on the Rocky Linux system.

By default, Java does not come installed on Rocky Linux App stream, you will need to install these manually. Now download the OpenJDK version 16 from its official website using the following command:

curl -O
tar -xvf openjdk-16.0.2_linux-x64_bin.tar.gz

Then, move the extracted directory to the /opt directory:

mv jdk-16.0.2 /opt/

Next, add the Java path to the .bashrc file:

nano ~/.bashrc

Add the following content:

export JAVA_HOME=/opt/jdk-16.0.2
export PATH=$PATH:$JAVA_HOME/bin

Save and close the file also activate the Java with the following command below:

source ~/.bashrc

Java 16 is now installed. To confirm, use the following commands:

java --version


java version "16.0.4" 2021-09-01
Java(TM) SE Runtime Environment (build 16.0.4+7-67)
Java HotSpot(TM) 64-Bit Server VM (build 16.0.4+7-67, mixed mode, sharing)

That’s all you need to do to install Java on Rocky Linux 8. I hope you find this quick tip helpful. For further reading on Install Java 16 (OpenJDK 16), please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.