Set up OpenJDK 19 on AlmaLinux 8

In this guide, we want to show you to Set up or Install OpenJDK 19 (Java 19) on AlmaLinux 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 features in the incubator and preview phases.

Steps To Set up OpenJDK 19 on AlmaLinux 8

To complete this guide, 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 AlmaLinux 8.

Install Java 19 on AlmaLinux 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 the 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 AlmaLinux 8 by checking its version:

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

Install Java SE Development Kit 19 on AlmaLinux 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
Output
warning: jdk-19_linux-x64_bin.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:jdk-19-2000:19.0.2-7             ################################# [100%]

Confirm the Java installation on AlmaLinux 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

Test Java 19 Installation on AlmaLinux 8

At this point, we will show you to create a sample project to see that your Java 19 is working correctly on AlmaLinux 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

At this point, you have learned to Set up or Install OpenJDK 19 (Java 19) on AlmaLinux 8.

Hope you enjoy it. You may be like these guides on the Orcacore website:

Install Go Language on AlmaLinux 8

Install and Configure OpenNMS on AlmaLinux 8

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!