Installing OpenJDK from the Red Hat-family repositories gives a server or workstation the JDK tools needed to compile and run Java code 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 current OpenJDK 21 development package is java-21-openjdk-devel on RHEL and compatible dnf based distributions. It installs javac, java, and supporting development tools under /usr/lib/jvm while leaving package updates to the enabled AppStream or distribution repositories.

Choose the JDK when 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 matching JRE package instead, and hosts with more than one major Java release should use alternatives only after the required packages are installed.

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

  1. Open a terminal with sudo privileges.
  2. Confirm that the OpenJDK 21 development 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 subscribed RHEL hosts, make sure the standard AppStream repository is enabled before installing packages. CentOS Stream, Rocky Linux, AlmaLinux, and Fedora use their equivalent enabled dnf repositories.

  3. Install the OpenJDK 21 JDK package.
    $ 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!

    Use java-17-openjdk-devel, java-11-openjdk-devel, or java-1.8.0-openjdk-devel only when an application specifically requires that major version. Newer Fedora releases 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 installed OpenJDK build.
    $ 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 default Java runtime when multiple major versions are installed.
    $ sudo alternatives --config java

    The alternatives prompt appears only when more than one provider is installed. Repeat with sudo alternatives --config javac if the compiler default also needs to change.