How to Install OpenJDK 21 on AlmaLinux 10

Published: 2026-06-24
Google AdSense 广告位 (待申请通过后开启)

Introduction

Java 21 is the latest Long-Term Support (LTS) release of the Java platform. It introduces performance improvements, virtual threads, enhanced pattern matching, and long-term maintenance support.

This guide explains how to install OpenJDK 21 on AlmaLinux 10 and verify that the installation is working correctly.

Prerequisites

Before starting, ensure that:

* You are running AlmaLinux 10.

* You have sudo or root privileges.

* Your system packages are up to date.

Update the system:

sudo dnf update -y

Check Available Java Packages

Search for available Java packages:

sudo dnf search openjdk

You should see OpenJDK 21 packages in the repository.

Install OpenJDK 21

Install Java 21:

sudo dnf install java-21-openjdk java-21-openjdk-devel -y
Image-1
Image-1

The package includes:

* Java Runtime Environment (JRE)

* Java Development Kit (JDK)

* Compiler tools such as javac

Verify the Installation

Check the Java version:

java -version
Image-2
Image-2

Example output:

openjdk version "21"
OpenJDK Runtime Environment
OpenJDK 64-Bit Server VM

Verify the compiler:

javac -version

Expected output:

javac 21.0.11

Locate the Java Installation Directory

Display the Java binary path:

which java

Find the actual installation location:

readlink -f $(which java)

Typical installation path:

/usr/lib/jvm/java-21-openjdk

Configure JAVA_HOME

Most applications can automatically detect the Java installation path. However, some enterprise software may still require JAVA_HOME to be configured manually.

Open the profile file:

sudo vi /etc/profile.d/java.sh

Add the following lines:

export JAVA_HOME=/usr/lib/jvm/java-21-openjdk
export PATH=$JAVA_HOME/bin:$PATH

Apply the changes:

source /etc/profile.d/java.sh

Verify:

echo $JAVA_HOME

Test Java

Create a test file:

vi HelloWorld.java

Insert:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello AlmaLinux 10");
    }
}

Compile:

javac HelloWorld.java

Run:

java HelloWorld

Output:

Hello AlmaLinux 10
Image-3
Image-3

Conclusion

Installing OpenJDK 21 on AlmaLinux 10 is straightforward using the default DNF repositories. After installation, verify the Java version, configure JAVA_HOME if needed, and run a simple program to confirm that the environment is working correctly.

Related AlmaLinux 10 Tutorials

How to Install Maven on AlmaLinux 10

How to Install Gradle on AlmaLinux 10

How to Install Git on AlmaLinux 10

Explore More

Technology Guides →

Java 21 Virtual Threads vs Java 17 Thread Pools in Swing Applications

Southeast Asia Insights →