How to Install Java 16 (OpenJDK 16) on Rocky Linux 8

Java is a general-purpose, class-based, object-oriented multipurpose programming language that is popular due to the design of having lesser implementation dependencies, meaning that the compiled Java code can be run on all platforms that support Java without the need for recompilation. Java is also fast, secure, and reliable, therefore. It is widely used for developing Java applications in laptops, data centers, game consoles, scientific supercomputers, cell phones, etc.

In the following tutorial, you will learn how to install the latest Java 16 (OpenJDK 16) on Rocky Linux 8.


  • Recommended OS: Rocky Linux 8.+.
  • User account: A user account with sudo or root access.
  • Required Packages: curl

Update Operating System

Update your Rocky Linux operating system to make sure all existing packages are up to date:

sudo dnf upgrade --refresh -y

The tutorial will be using the sudo command and assuming you have sudo status.

To verify sudo status on your account:

sudo whoami

Example output showing sudo status:

[joshua@rockylinux ~]$ sudo whoami

If you have not set up a sudo user account and would like to, visit our tutorial on How to Add a User to Sudoers on Rocky Linux.

To use the root account, use the following command with the root password to log in.


Install Curl Package

You will need to have curl installed for this tutorial. To find out if you have curl, use the following:

curl --version

Example output:

[joshua@localhost ~]$ curl --version
curl 7.61.1 (x86_64-redhat-linux-gnu) libcurl/7.61.1 OpenSSL/1.1.1g zlib/1.2.11 brotli/1.0.6 libidn2/2.2.0 libpsl/0.20.2 (+libidn2/2.2.0) libssh/0.9.4/openssl/zlib nghttp2/1.33.0
Release-Date: 2018-09-05

To install curl if it is missing, execute the following command:

sudo dnf install curl -y

Note, installing curl without checking will not harm either.

Install (OpenJDK 16)

By default, Java does not come installed on Rocky Linux App stream, and to find specific versions of Java such as the latest 16.0.2, you will need to install these manually. However, the process is relatively easy.

Download Latest Java 16 Build

Visit the downloads page to get the latest build version link, then use the following curl command:

curl  -O

Once the download is complete, you need to extract the archive as follows:

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

Configure and Install Java 16

Next, move the extracted archive directory into the /opt/ location:

sudo mv jdk-16.0.2 /opt/

Now you need to set the environment variables as below:

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

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

java --version

If installed correctly, you should see the following output:

How to Install Java 16 (OpenJDK 16) on Rocky Linux

As you can see, you can see the version is the latest 16.0.2 build.

Testing Java Installation

To finish off, it is always handy to test installations of these kinds to confirm everything is working correctly after being installed. The easy way is to create a small program script to try using the famous Hello World.

First, create the Java program file as follows

sudo nano

Next, add the following Java code into the file:

public class hello {
  public static void main(String[] args) {
    System.out.println("G'day from LinuxCapable!");

Save the file (CTRL+O), then exit (CTRL+X).

Next, compile the code:


Finally, run the Java code with the following command:

java hello

Example output:

How to Install Java 16 (OpenJDK 16) on Rocky Linux

Congratulations, everything is working correctly.

Comments and Conclusion

In the tutorial, you have learned how to download and install Java 16 (OpenJDK 16) latest version, along with downloading and future versions and installing with the same process for your Rocky Linux 8 operating system.


Like to get automatic updates? Follow us on one of our social media accounts!