How to install OpenJDK on Red Hat, CentOS, and Fedora

InstallingOpenJDKfrom the Red Hat-⁠family repositories gives a server or workstation theJDKtools needed to compile and runJavacode without a manual archive install. The package-⁠manager path keeps the compiler, runtime, security updates, and system-⁠wide defaults under the operating system's control.

The currentOpenJDK 21development package is java-⁠21-⁠openjdk-⁠devel onRHELand compatiblednfbased distributions. It installs javac, java, and supporting development tools under/usr/lib/jvmwhile leaving package updates to the enabledAppStreamor distribution repositories.

Choose theJDKwhen the host builds code, runs build tools that need javac, or needs development utilities such as jar and javadoc. Runtime-⁠only hosts can use the matchingJREpackage instead, and hosts with more than one majorJavarelease should usealternativesonly after the required packages are installed.

Related: How to install Java Runtime Environment (JRE) on Red Hat, CentOS Stream, and Fedora
Related: How to set JAVA_HOME on Linux
Related: How to check the installed Java version on Linux

Steps to install OpenJDK on Red Hat, CentOS, and Fedora:

  1. Open a terminal with sudo privileges.

  2. Confirm that theOpenJDK 21development package is available from the enabled repositories.
    $ dnf search --all java-21-openjdk-devel ================= Name Exactly Matched: java-21-openjdk-devel ================== java-21-openjdk-devel.x86_64 : OpenJDK 21 Development Environment

    On subscribedRHELhosts, make sure the standardAppStreamrepository is enabled before installing packages.CentOS Stream,Rocky Linux,AlmaLinux, andFedorause their equivalent enableddnfrepositories.

  3. Install theOpenJDK 21 JDKpackage.
    $ sudo dnf install --assumeyes java-21-openjdk-devel Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: java-21-openjdk-devel x86_64 1:21.0.11.0.10-2.el9 appstream 5.0 M Installing dependencies: java-21-openjdk x86_64 1:21.0.11.0.10-2.el9 appstream 401 k java-21-openjdk-headless x86_64 1:21.0.11.0.10-2.el9 appstream 49 M Transaction Summary ================================================================================ Install 3 Packages ##### snipped ##### Complete!

    Usejava-⁠17-⁠openjdk-⁠devel,java-⁠11-⁠openjdk-⁠devel, orjava-⁠1.8.0-⁠openjdk-⁠develonly when an application specifically requires that major version. NewerFedorareleases can also provide newer non-⁠LTS packages.

  4. Verify that the compiler is installed.
    $ javac -version javac 21.0.11
  5. Verify that the runtime uses the installedOpenJDKbuild.
    $ java -version openjdk version "21.0.11" 2026-04-21 LTS OpenJDK Runtime Environment (Red_Hat-21.0.11.0.10-1) (build 21.0.11+10-LTS) OpenJDK 64-Bit Server VM (Red_Hat-21.0.11.0.10-1) (build 21.0.11+10-LTS, mixed mode, sharing)
  6. Check the installed package records if the binary versions do not match what you expected.
    $ dnf list installed java-21-openjdk-devel java-21-openjdk Installed Packages java-21-openjdk.x86_64 1:21.0.11.0.10-2.el9 @appstream java-21-openjdk-devel.x86_64 1:21.0.11.0.10-2.el9 @appstream
  7. Select the defaultJavaruntime when multiple major versions are installed.
    $ sudo alternatives --config java

    Thealternativesprompt appears only when more than one provider is installed. Repeat withsudo alternatives --config javacif the compiler default also needs to change.