How to Install Java 16 in Rocky Linux and AlmaLinux

Java is a cross-platform, object-oriented, and multipurpose programming language that is primarily used for creating mobile, web, and cloud applications. Additionally, you can use Java to create games, chatbots, enterprise applications, and a whole lot more.

To develop Java applications, you need to install an IDE (Integrated Development Environment). IntelliJ IDEA is a perfect example of an IDE that is designed specifically for the development of Java applications. However, you need to have Java installed beforehand. This can be provided by either the OpenJDK (Open Java Development Kit) or Oracle JDK (Oracle Development Kit).

[ You might also like: 27 Best IDEs for C/C++ Programming or Source Code Editors on Linux ]

OpenJDK is an open-source implementation of the Java SE. It’s a development environment that was initially created by Sun Microsystems and is currently sponsored and maintained by Oracle. OpenJDK constitutes the Java compiler, Java Runtime Environment (JRE), Java Virtual Machine (JVM), and Java class library.

At the time of writing this guide, the latest version of Java is Java 16, which is provided by OpenJDK 16. Join us as we examine how you can install Java 16 on Rocky Linux 8 (also works on AlmaLinux 8).

Installing Java (OpenJDK) in Rocky Linux

To get started, we need to confirm that Java is not yet installed by running the following command.

$ java --version

bash: java: command not found...

Next, we are going to download the OpenJDK 16 binary file which comes as a tarball file using the following curl command.

$ curl  -O

Once the download is complete, extract the compressed binary file.

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

Then move the decompressed folder to the /opt directory as shown.

$ sudo mv jdk-16.0.2 /opt

Thereafter, set the environment variables as shown.

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

Java is now installed. To confirm the version installed, run the following commands:

$ echo $JAVA_HOME
$ java --version
Check Java Version in Rocky Linux
Check Java Version in Rocky Linux

Testing Java (OpenJDK) in Rocky Linux

To test if Java was correctly installed and working, we will code a simple Java program that adds two integers as follows.

$ sudo vim

Paste the following lines of code and save the file.

public class Hello {

    public static void main(String[] args) {
        // Adds two numbers
        int x = 45;
        int y = 100;
        int z = x + y;
        System.out.println("Hello, the sum of the two numbers is: " +z);


Compile the Java code;

$ javac

Then run the Java code

$ java Hello
Testing Java in Rocky Linux
Testing Java in Rocky Linux

Great, all seems fine. We have successfully installed OpenJDK 16 and tested it by compiling and running a simple Java program in Rocky Linux.

Tutorial Feedback...
Was this article helpful? If you don't find this article helpful or found some outdated info, issue or a typo, do post your valuable feedback or suggestions in the comments to help improve this article...

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.