Best Steps to Install OpenJDK 17 on AlmaLinux 9 – OrcaCore
This tutorial is designed to guide you through the process of installing OpenJDK 17 on AlmaLinux 9. OpenJDK (Open Java Development Kit) is the open-source implementation of the Java Development Kit (JDK). Being open-source, OpenJDK is freely available under the GNU General Public License. Follow these steps provided by OrcaCore to successfully set up OpenJDK 17 on your AlmaLinux 9 system.
Before you begin with this guide on OpenJDK 17 and AlmaLinux 9, ensure you are logged into your server as a non-root user with sudo
privileges. If you haven’t already configured this, you can refer to our guide on Initial Server Setup with AlmaLinux 9 for assistance.
1. Install OpenJDK 17 AlmaLinux 9
The first step involves updating your local package index to ensure you have the latest information about available packages.
sudo dnf update -y
Download OpenJDK 17
Visit the JDK Downloads page to find the latest archive of Java 17. Use the wget
command to download the appropriate archive for your system.
sudo wget https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz
Once the download is complete, extract the archive using the following command:
sudo tar xvf openjdk-17.0.2_linux-x64_bin.tar.gz
Next, move the extracted directory to the /opt
directory, which is a common location for installing software.
sudo mv jdk-17.0.2 /opt/
Configure Java Environment Path
Now, configure the Java home path by creating a shell script in /etc/profile.d/
to set the JAVA_HOME
and add the Java binaries to your system’s PATH
.
sudo tee /etc/profile.d/jdk17.sh <<EOF
export JAVA_HOME=/opt/jdk-17.0.2
export PATH=$PATH:$JAVA_HOME/bin
EOF
After creating the script, source it to apply the changes to your current session.
source /etc/profile.d/jdk17.sh
Verify that the JAVA_HOME
environment variable is correctly set.
echo $JAVA_HOME

Finally, verify the Java installation by checking its version.
java -version

2. Install Java SE Development Kit 17 on AlmaLinux 9
Alternatively, you can install Java SE Development Kit 17 from Oracle. 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

Confirm the Java installation on AlmaLinux 9:
java -version

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
To ensure your Java 17 installation is working correctly, create a simple "Hello, World" project.
Create and open the HelloWorld.java
file with your favorite text 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");
}
}
Save and close the file. Then, compile and run your Java code:
javac HelloWorld.java
java HelloWorld
<strong><mark>Output</mark></strong>
Hello, World
That’s it, you are done. You have successfully installed and tested OpenJDK 17 on AlmaLinux 9.
Conclusion
This guide has shown you how to install OpenJDK 17 (Java 17) on AlmaLinux 9 using two methods: downloading directly from the OpenJDK website and installing the Oracle JDK RPM package. This straightforward process will enable you to run Java applications on your AlmaLinux 9 system. Remember to subscribe to OrcaCore on Facebook and Twitter for more helpful tutorials.
You might also find these articles interesting:
- 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
Alternative Installation Methods for OpenJDK 17 on AlmaLinux 9
While the above methods are effective, let’s explore two alternative approaches for installing OpenJDK 17 on AlmaLinux 9.
1. Using the jenv
Tool
jenv
is a command-line tool that allows you to manage multiple Java versions on your system. This can be useful if you need to switch between different JDK versions for different projects.
Installation:
First, you’ll need to install jenv
. Since it’s not directly available in the AlmaLinux repositories, we’ll use git
to clone the repository and then configure it. You may first need to install git
:
sudo dnf install git -y
Then, clone the jenv
repository:
git clone https://github.com/jenv/jenv.git ~/.jenv
Next, add jenv
to your PATH
by adding the following lines to your ~/.bashrc
or ~/.zshrc
file:
echo 'export JENV_ROOT="$HOME/.jenv"' >> ~/.bashrc
echo 'export PATH="$JENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(jenv init -)"' >> ~/.bashrc
Source your shell configuration file to apply the changes:
source ~/.bashrc
Installing OpenJDK 17 with jenv
:
Now that jenv
is installed, you can use it to install OpenJDK 17. First, download and extract the OpenJDK 17 archive as described in the original article. Then, add it to jenv
:
jenv add /opt/jdk-17.0.2
You can now set the global Java version to OpenJDK 17:
jenv global openjdk-17.0.2
Verify the Java version:
java -version
This method provides a flexible way to manage multiple Java versions, making it easier to switch between them as needed.
2. Using SDKMAN!
SDKMAN! (Software Development Kit Manager) is another popular tool for managing multiple software development kits, including Java. It simplifies the installation and management of various JDK versions.
Installation:
Install SDKMAN! by running the following command:
curl -s "https://get.sdkman.io" | bash
Follow the on-screen instructions to complete the installation. You may need to open a new terminal or source your shell configuration file.
source "$HOME/.sdkman/bin/sdkman-init.sh"
Installing OpenJDK 17 with SDKMAN!:
Use SDKMAN! to install OpenJDK 17. First, search for available Java versions:
sdk list java
Find the OpenJDK 17 distribution you prefer (e.g., GraalVM, Liberica, etc.) and install it using its identifier:
sdk install java 17.0.2-graal
Replace 17.0.2-graal
with the actual identifier of the OpenJDK 17 distribution you want to install.
Set the installed Java version as the default:
sdk default java 17.0.2-graal
Verify the Java version:
java -version
SDKMAN! provides a convenient way to install and manage multiple JDK versions, along with other software development kits, streamlining your development environment setup. This alternative method for installing OpenJDK 17 is very effective.