AlmaLinux

Install Java 25 / Java 21 (OpenJDK) on Rocky Linux 10 / AlmaLinux 10

OpenJDK is the open source implementation of the Java Platform, Standard Edition. Rocky Linux 10 and AlmaLinux 10 ship with two LTS versions in their default repositories: OpenJDK 21 and OpenJDK 25. The older LTS versions (8, 11, 17) are no longer available in the RHEL 10 repos.

This guide covers installing Java 25 (the latest LTS) and Java 21 on Rocky Linux 10 / AlmaLinux 10, setting the default Java version, and configuring JAVA_HOME. For the full OpenJDK release schedule, see the OpenJDK 25 project page.

Prerequisites

  • A server or VM running Rocky Linux 10 or AlmaLinux 10
  • Root or sudo access

Available Java Versions on Rocky Linux 10 / AlmaLinux 10

Check which OpenJDK packages are available in the default repositories.

sudo dnf list available java-*-openjdk java-*-openjdk-devel

RHEL 10 family provides:

PackageVersionType
java-21-openjdk21.x (LTS)JRE only
java-21-openjdk-devel21.x (LTS)JDK (includes compiler)
java-25-openjdk25.x (LTS)JRE only
java-25-openjdk-devel25.x (LTS)JDK (includes compiler)

Step 1: Install Java 25 (OpenJDK 25) on Rocky Linux 10 / AlmaLinux 10

Install the JDK package if you need to compile Java code. Install just the JRE if you only need to run Java applications.

Install JDK 25 (recommended for development):

sudo dnf install -y java-25-openjdk java-25-openjdk-devel

Or install JRE 25 only (for running applications):

sudo dnf install -y java-25-openjdk

Verify the installation.

$ java -version
openjdk version "25.0.2" 2026-01-21 LTS
OpenJDK Runtime Environment (Red_Hat-25.0.2.0.10) (build 25.0.2+10-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-25.0.2.0.10) (build 25.0.2+10-LTS, mixed mode, sharing)

If you installed the JDK, confirm the compiler is available.

$ javac -version
javac 25.0.2

Step 2: Install Java 21 (OpenJDK 21) – Alternative

If your application requires Java 21 (many enterprise apps like Apache Tomcat, Elasticsearch, and Jenkins still target 21), install it alongside or instead of 25.

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

Step 3: Set Default Java Version

If you have multiple Java versions installed, use alternatives to set the default.

sudo alternatives --config java

This shows a numbered list of installed Java versions. Enter the number for the version you want as default.

$ sudo alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           java-25-openjdk.x86_64 (/usr/lib/jvm/java-25-openjdk-25.0.2.0.10-1.el10.x86_64/bin/java)
   2           java-21-openjdk.x86_64 (/usr/lib/jvm/java-21-openjdk-21.0.10.0.7-1.el10.x86_64/bin/java)

Enter to keep the current selection[+], or type selection number:

Do the same for javac if you have multiple JDKs.

sudo alternatives --config javac

Step 4: Set JAVA_HOME Environment Variable

Many applications (Maven, Gradle, Tomcat, Jenkins) require JAVA_HOME to be set. Find the Java installation path first.

$ dirname $(dirname $(readlink -f $(which java)))
/usr/lib/jvm/java-25-openjdk-25.0.2.0.10-1.el10.x86_64

Set JAVA_HOME system-wide by creating a profile script.

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

Add the following content:

export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH=$JAVA_HOME/bin:$PATH

Make it executable and load it.

sudo chmod +x /etc/profile.d/java.sh
source /etc/profile.d/java.sh

Verify JAVA_HOME is set correctly.

$ echo $JAVA_HOME
/usr/lib/jvm/java-25-openjdk-25.0.2.0.10-1.el10.x86_64

This approach dynamically follows the alternatives symlink, so when you switch the default Java version with alternatives --config java, JAVA_HOME updates automatically on next login.

Step 5: Quick Test

Create a simple Java program to verify the JDK is working.

vi Hello.java

Add the following:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Java " + System.getProperty("java.version") + " is working on " + System.getProperty("os.name"));
    }
}

Compile and run.

$ javac Hello.java
$ java Hello
Java 25.0.2 is working on Linux

Clean up the test file.

rm -f Hello.java Hello.class

Conclusion

Java (OpenJDK 25 or 21) is installed and configured on Rocky Linux 10 / AlmaLinux 10. With JAVA_HOME set, you can now install build tools like Apache Maven or deploy application servers like Apache Tomcat. For managing multiple Java versions across projects, the alternatives system handles it cleanly without third-party tools.

Related Articles

Cloud Install OpenStack on Rocky Linux 8 – Setup Keystone (Step 3) AlmaLinux Install Caddy Web Server on Rocky / AlmaLinux 9|8 CentOS Secure FreeIPA Server With Let’s Encrypt SSL Certificate Monitoring Install LibreNMS on Rocky Linux 10 / AlmaLinux 10

Press ESC to close