Best Steps to Install OpenJDK 17 on AlmaLinux 9

This tutorial intends to teach you to Install OpenJDK 17 on AlmaLinux 9. (OPEN Java Development Kit) The open-source implementation of the Java Development Kit (see JDK). OpenJDK is available for free with a GNU General Public license. Now proceed to the following guide steps on the Orcacore website to set up OpenJDK 17 AlmaLinux 9.

Steps To Install OpenJDK 17 on AlmaLinux 9

To complete this guide for OpenJDK 17 AlmaLinux 9, 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 AlmaLinux 9.

1. Install OpenJDK 17 AlmaLinux 9

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

sudo dnf update -y

Download OpenJDK 17

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

sudo wget https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz

Then, extract your downloaded file with the command below:

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

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

sudo mv jdk-17.0.2 /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/jdk17.sh <<EOF
export JAVA_HOME=/opt/jdk-17.0.2
export PATH=\$PATH:\$JAVA_HOME/bin
EOF

Source your profile file with the following command:

source /etc/profile.d/jdk17.sh

Verify your Java Home path:

echo $JAVA_HOME
Verify Java Home path for OpenJDK 17 AlmaLinux 9

Also, you can verify your Java installation by checking its version:

java -version
Verify Java version AlmaLinux 9

2. Install Java SE Development Kit 17 on AlmaLinux 9

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

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

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

sudo rpm -Uvh jdk-17_linux-x64_bin.rpm
Download Java SE 17 AlmaLinux 9

Confirm the Java installation on AlmaLinux 9:

java -version
Verify Java SE 17 AlmaLinux 9

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 Java 17

At this point, we will show you how to create a sample project to see that your Java 17 is working correctly on AlmaLinux 9.

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 Install OpenJDK 17 (Java 17) on AlmaLinux 9 with this straightforward process. Hope you enjoy it. Please subscribe to us on Facebook and Twitter.

Also, you may like to read the following articles:

Install Flask Python AlmaLinux 9

Virtualbox setup on Almalinux 9 command line

Remmina Installation AlmaLinux 9

AlmaLinux 9 Install Dot Net Core

Elasticsearch Setup AlmaLinux 9

Apache CouchDB Setup For AlmaLinux 9

Share your love

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!