Install OpenJDK 19 on Rocky Linux 8: Free JDK

This guide intends to teach you to Install OpenJDK 19 on Rocky Linux 8. OpenJDK 19 is a production-ready and open-source distribution of Java Development Kit (JDK) version 19, which was released on September 20th, 2022. JDK 19 is a scheduled update as per Oracle’s 6-month release cadence. It doesn’t come with breaking changes – with almost all features in the incubator and preview phases. Now follow the guide steps below on the Orcacore website to set up OpenJDK 19 Rocky Linux 8.

Steps To Install OpenJDK 19 on Rocky Linux 8

To Download OpenJDK 19 and install it on Rocky Linux 8, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Rocky Linux 8.

1. OpenJDK 19 Setup on Rocky Linux 8

First, you need to update your local package index with the command below:

sudo dnf update -y

Then install the required packages by using the following command:

sudo dnf install curl wget tar -y

Download OpenJDK 19

At this point, you need to visit the JDK Downloads page to download OpenJDK 19 latest archive by using the wget command:

sudo wget https://download.java.net/java/GA/jdk19.0.1/afdd2e245b014143b62ccb916125e3ce/10/GPL/openjdk-19.0.1_linux-x64_bin.tar.gz

Then, extract your downloaded file with the command below:

sudo tar xvf openjdk-19.0.1_linux-x64_bin.tar.gz

Next, move your extracted file to the /opt directory:

sudo mv jdk-19.0.1 /opt/

Configure Java Environment Path

At this point, you need to configure the Java home path by using the following command:

sudo tee /etc/profile.d/jdk19.sh <<EOF
export JAVA_HOME=/opt/jdk-19.0.1
export PATH=\$PATH:\$JAVA_HOME/bin
EOF

Source your profile file with the following command:

source /etc/profile.d/jdk19.sh

Verify your Java Home path:

echo $JAVA_HOME
Output
/opt/jdk-19.0.1

Also, you can verify your Java 19 installation on Rocky Linux 8 by checking its version:

java -version
Download OpenJDK 19 Rocky Linux 8

2. Set up Java SE Development Kit 19 on Rocky Linux 8

If you choose to go with Java SE Development Kit 19, download the RPM package for CentOS / RHEL / Fedora system using the command below:

sudo wget https://download.oracle.com/java/19/latest/jdk-19_linux-x64_bin.rpm

Then, install the RPM package using the yum or rpm command:

sudo rpm -Uvh jdk-19_linux-x64_bin.rpm
Install OpenJDK 19 on Rocky Linux 8

Confirm the Java installation on Rocky Linux 8:

java -version
Output
openjdk version "19.0.2" 2022-10-18
OpenJDK Runtime Environment (build 19.0.2+10-21)
OpenJDK 64-Bit Server VM (build 19.0.2+10-21, mixed mode, sharing)

Configure the Java environment with the command below:

cat <<EOF | sudo tee /etc/profile.d/jdk.sh
export JAVA_HOME=/usr/java/default
export PATH=\$PATH:\$JAVA_HOME/bin
EOF

To use Java Home, source the file by using the following command:

source /etc/profile.d/jdk.sh

3. Create a Sample Project with OpenJDK 19

At this point, we will show you how to create a sample project to see that your Java 19 is working correctly on Rocky Linux 8.

Create and open the hello world file with your favorite text editor, here we use the vi editor:

vi HelloWorld.java

Add the following content to the file:

public class HelloWorld {

    public static void main(String[] args) {
        // Prints "Hello, World" to the terminal window.
        System.out.println("Hello, World");
    }

}

When you are done, save and close the file.

Then, compile and run your Java code:

java HelloWorld.java
Output
Hello, World

That’s it, you are done.

Conclusion

OpenJDK 19 provides the tools, libraries, and runtime needed to develop and run Java applications. At this point, you have learned to Install OpenJDK 19 (Java 19) on Rocky Linux 8.

Hope you enjoy it. You may also like these guides:

PostgreSQL 15 For Rocky Linux 8

How To Install Yarn on Rocky Linux 8

Install Latest PostgreSQL on Rocky Linux 8

Nginx Web Server Setup Rocky Linux 8

Nodejs Setup Rocky Linux 8

Ntopng Monitoring For Rocky Linux 8

Share your love

Stay informed and not overwhelmed, subscribe now!