Java on RHEL, Rocky Linux, AlmaLinux, CentOS Stream, Oracle Linux, and Fedora usually means OpenJDK RPMs from the distribution’s enabled repositories—free, updated through the operating system, and integrated with the alternatives system. When your release does not ship the Java major you need, add Eclipse Temurin from Adoptium or install Oracle JDK from a vendor tarball.
This guide covers OpenJDK with dnf, JRE and headless variants, Temurin on Rocky Linux 10.2, Oracle JDK from a tarball, alternatives version switching, JAVA_HOME, a compile-and-run check, update paths, and uninstall steps per method.
Tested on: Rocky Linux 10.2 (Red Quartz); OpenJDK 21.0.11 (
java-21-openjdk-devel); Temurin 17.0.19 (temurin-17-jdkfrom Adoptiumrhel/10repository).
JDK, JRE, and package names on RHEL-family Linux
Java terminology overlaps in documentation and RPM names. The table below maps common terms to what you install on Enterprise Linux.
| Term | What it means | When you need it |
|---|---|---|
| JVM | Java Virtual Machine—the runtime engine that executes bytecode | Present with any installed Java package; you rarely install “JVM” as a separate product |
| JRE | Java Runtime Environment—runs compiled Java programs (java) |
Application servers or services that only execute JARs and WARs and never compile code |
| JDK | Java Development Kit—JRE plus compiler and development tools (javac, headers) |
Building Java code, Maven, Gradle, JasperReports Buildomatic, or any workflow that compiles |
| Headless | Runtime without graphical UI libraries (AWT/Swing peers) | Servers and containers; smallest footprint for backend Java processes |
| OpenJDK | Open-source Java implementation packaged and maintained through your distribution repositories | Default choice when the repository supplies the major version your application requires |
| Temurin | Eclipse Adoptium’s tested OpenJDK distribution | When your distribution repos do not ship the Java major you need |
| Oracle JDK | Oracle’s JDK distribution | When your organization requires Oracle support, licensing terms, or vendor-specific tooling |
On RPM-family Linux, package names do not always mirror the major version number literally. Java 8 commonly uses java-1.8.0-openjdk, while newer majors use names such as java-17-openjdk and java-21-openjdk. Search the exact naming your release publishes before you install.
When you are unsure whether you need a JRE or JDK, install the JDK (java-<version>-openjdk-devel). Red Hat OpenJDK documentation recommends the JDK when you are unsure; Fedora includes OpenJDK as its default open-source Java implementation. Graphical export features in applications such as JasperReports Server can still need fonts, a browser, or other dependencies even when the Java process itself runs headless on the server.
Choose an install method
| Method | Best for | Jump to |
|---|---|---|
OpenJDK from dnf |
Default on RHEL-family Linux—development (-devel) or runtime |
Method 1 |
| JRE or headless OpenJDK | Application servers and containers that only run Java programs | Method 2 |
| Eclipse Temurin (Adoptium) | Java majors missing from your distribution repos (for example Java 17 on EL10) | Method 3 |
| Oracle JDK tarball | Oracle support contracts or vendor-specific tooling | Method 4 |
Most readers should install java-<version>-openjdk-devel from their distribution repositories when that version exists. Search the exact package naming used by your release; Java 8 commonly uses java-1.8.0-openjdk, while newer majors use names such as java-17-openjdk and java-21-openjdk. Add Temurin when dnf list available shows no matching OpenJDK package for your target major.
Prerequisites
- RHEL, Rocky Linux, AlmaLinux, CentOS Stream, Oracle Linux, or Fedora with sudo and outbound HTTPS for dnf and optional Adoptium repositories.
- Enough disk space—each full JDK is roughly 150–400 MB with dependencies.
- For Debian-family hosts, see install Java on Debian.
Refresh metadata with dnf makecache before you search or install:
sudo dnf makecacheCheck whether Java is already installed:
java -version 2>&1 || echo "java: not installed"
javac -version 2>&1 || echo "javac: not installed"Sample output when OpenJDK 21 is the active default:
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)
javac 21.0.11List OpenJDK packages your enabled repositories provide:
dnf list available 'java-*-openjdk*'For a compact package-name list:
dnf repoquery --available --qf '%{name}' 'java-*-openjdk*' | sort -uSample output on Rocky Linux 10.2:
java-21-openjdk
java-21-openjdk-devel
java-21-openjdk-headlessIf repoquery is unavailable, install the DNF plugins package your distribution documents for that release.
List installed OpenJDK packages separately to see what already owns the active alternative:
dnf list installed 'java-*-openjdk*'On Rocky Linux 10.2 AppStream publishes OpenJDK 21 packages such as those above. RHEL 9 and compatible rebuilds may also list java-17-openjdk, java-11-openjdk, or java-1.8.0-openjdk depending on release and repository access. For broader CLI reference beyond the dnf steps below, see the Linux commands index.
Method 1: Install OpenJDK from dnf (recommended)
Install the JDK when you compile Java code or run Buildomatic-style tooling. Replace 21 with the major version your application requires and your repositories publish:
sudo dnf install -y java-21-openjdk-develThe install completes with Complete! when dnf finishes without errors.
Verify the runtime and compiler:
java -versionSample output:
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)javac -versionSample output:
javac 21.0.11The java-21-openjdk-devel package pulls in the matching runtime and headless libraries. JVM files land under /usr/lib/jvm/java-21-openjdk/ on the tested host.
Method 2: Install JRE or headless OpenJDK
Use a runtime-only package when you do not need javac—typical for Tomcat hosts that only execute WAR files. Prefer the JDK when you compile code or run Buildomatic-style tooling.
| RPM package pattern | Meaning | Typical use |
|---|---|---|
java-<version>-openjdk-devel |
JDK with compiler and development tools | Maven, Gradle, JasperReports Buildomatic, or any compile step |
java-<version>-openjdk |
Full runtime with additional desktop or GUI-related dependencies | Java apps that may use GUI libraries on a desktop-capable host |
java-<version>-openjdk-headless |
Minimal runtime without graphical UI libraries | Backend services and containers where only bytecode execution is required |
Install a minimal headless runtime:
sudo dnf install -y java-21-openjdk-headlessConfirm only the runtime is required before you skip -devel—tools such as Maven, Gradle, and JasperReports Server Buildomatic need a JDK with javac. Server-side Java can be headless while JasperReports still needs separate browser or font packages for graphical PDF and dashboard export.
Method 3: Install Eclipse Temurin from Adoptium
When your distribution repositories do not ship your target Java major, add the Adoptium RPM repository. Adoptium’s Linux installation docs derive the distribution segment from /etc/os-release and note that unsupported distribution and version combinations may work only on a best-effort basis.
On the tested Rocky Linux 10.2 host, the automatically derived rocky/10 path was unavailable, while the rhel/10 path worked. The repository below therefore pins the tested RHEL-compatible path:
sudo tee /etc/yum.repos.d/adoptium.repo > /dev/null <<'EOF'
[Adoptium]
name=Adoptium
baseurl=https://packages.adoptium.net/artifactory/rpm/rhel/$releasever/$basearch
enabled=1
gpgcheck=1
gpgkey=https://packages.adoptium.net/artifactory/api/gpg/key/public
EOFOn Fedora or other releases, check Adoptium’s current repository tree and supported-platform list before you copy this file. AlmaLinux and CentOS Stream hosts may need the same rhel segment override when the OS ID path does not resolve.
Refresh Adoptium metadata and list available Temurin JDK packages:
sudo dnf makecache --disablerepo='*' --enablerepo=Adoptium
dnf list available 'temurin-*-jdk'Sample output:
temurin-11-jdk.x86_64 11.0.31.0.0.11-0 Adoptium
temurin-17-jdk.x86_64 17.0.19.0.0.10-0 Adoptium
temurin-21-jdk.x86_64 21.0.11.0.0.10-0 AdoptiumInstall the major you need—for example Java 17 on Rocky Linux 10 when the tested AppStream repositories had no java-17-openjdk:
sudo dnf install -y temurin-17-jdkVerify Temurin is registered and check its JVM path:
java -version
ls -ld /usr/lib/jvm/java-17-temurin-jdkSample output after switching the default with alternatives (see the next section):
openjdk version "17.0.19" 2026-04-21
OpenJDK Runtime Environment Temurin-17.0.19+10 (build 17.0.19+10)
OpenJDK 64-Bit Server VM Temurin-17.0.19+10 (build 17.0.19+10, mixed mode, sharing)
drwxr-xr-x. 9 root root 4096 Jul 12 11:36 /usr/lib/jvm/java-17-temurin-jdkFedora hosts may use the fedora Adoptium path from Adoptium Linux installation docs when rhel does not match your release.
Method 4: Install Oracle JDK from a tarball
Oracle JDK is not shipped in distribution repositories on RHEL-family Linux. Review Oracle licensing and support terms before you choose Oracle JDK for organizational deployment. Download the Linux x64 archive from Oracle Java downloads and extract it under /opt with tar:
sudo mkdir -p /opt/jdk
sudo tar -xf jdk-21_linux-x64_bin.tar.gz -C /opt/jdkRegister the binaries with alternatives—replace jdk-21 with your extracted directory name:
sudo alternatives --install /usr/bin/java java /opt/jdk/jdk-21/bin/java 2100
sudo alternatives --install /usr/bin/javac javac /opt/jdk/jdk-21/bin/javac 2100These commands register only java and javac. A complete JDK exposes additional tools such as jar, javadoc, jshell, and keytool. Register any additional commands your workflow requires, or invoke them through $JAVA_HOME/bin to avoid mixing tools from different JDKs.
Select and verify the Oracle build:
sudo alternatives --config java
sudo alternatives --config javac
java -version
javac -versionMost open-source workloads should prefer OpenJDK or Temurin (OpenJDK install guide).
Switch between installed JDKs
Fedora and RHEL-family packaging use the alternatives system to switch installed Java implementations. When multiple JDK packages are installed, alternatives manages the /usr/bin/java and /usr/bin/javac symlinks separately—selecting Java 17 for java does not necessarily select Java 17 for javac.
List registered JVMs:
alternatives --display java | head -20Sample output (trimmed):
link currently points to /usr/lib/jvm/java-21-openjdk/bin/java
/usr/lib/jvm/java-21-openjdk/bin/java - priority 21001110
/usr/lib/jvm/java-17-temurin-jdk/bin/java - priority 1161Switch both runtime and compiler interactively:
sudo alternatives --config java
sudo alternatives --config javacVerify both binaries point at the same major version:
java -version
javac -version
readlink -f "$(command -v java)"
readlink -f "$(command -v javac)"Or set a specific path—Temurin 17 on the tested host:
sudo alternatives --set java /usr/lib/jvm/java-17-temurin-jdk/bin/java
sudo alternatives --set javac /usr/lib/jvm/java-17-temurin-jdk/bin/javac
java -version
javac -versionReturn to distribution OpenJDK 21:
sudo alternatives --set java /usr/lib/jvm/java-21-openjdk/bin/java
sudo alternatives --set javac /usr/lib/jvm/java-21-openjdk/bin/javac
java -versionTo return the runtime and compiler to automatic priority-based selection, run:
sudo alternatives --auto java
sudo alternatives --auto javacThen verify both versions with java -version and javac -version.
Set JAVA_HOME
Build tools and application servers expect JAVA_HOME to point at the JVM root, not the bin/java file. Resolve the active binary with command -v and readlink before you export the path:
readlink -f "$(command -v java)"Sample output:
/usr/lib/jvm/java-21-openjdk/bin/javaDerive and export JAVA_HOME:
export JAVA_HOME="$(dirname "$(dirname "$(readlink -f "$(command -v java)")")")"
echo "$JAVA_HOME"Sample output:
/usr/lib/jvm/java-21-openjdkPersist JAVA_HOME for login shells:
echo "export JAVA_HOME=$JAVA_HOME" | sudo tee /etc/profile.d/java.sh
sudo chmod 644 /etc/profile.d/java.shThis stores a fixed JDK path. Changing the java alternative later does not automatically update JAVA_HOME—update the profile file or service configuration when you switch the required JDK. That distinction matters for Tomcat, Maven, Gradle, and JasperReports Buildomatic.
Files under /etc/profile.d/ are loaded by compatible login or interactive shells. A systemd service does not normally source them. For a service, add the variable to its unit or drop-in:
[Service]
Environment="JAVA_HOME=/usr/lib/jvm/java-21-openjdk"Reload the unit configuration after you edit the file:
sudo systemctl daemon-reload
sudo systemctl restart SERVICEReplace SERVICE with your unit name, such as tomcat. Some applications also support EnvironmentFile= when they already read a dedicated environment file.
Confirm the directory exists before you hard-code a path in unit files:
ls -ld /usr/lib/jvm/java-21-openjdk*Verify Java with a sample program
Compile and run a short program to confirm javac and java use the same JDK:
cat > /tmp/Hello.java <<'EOF'
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Java on Rocky Linux");
}
}
EOF
javac /tmp/Hello.java
java -cp /tmp HelloSample output:
Hello, Java on Rocky LinuxRemove the test files when you are done:
rm -f /tmp/Hello.java /tmp/Hello.classUpdate Java packages
Distribution OpenJDK packages update with normal dnf maintenance:
sudo dnf upgrade 'java-*-openjdk*'Temurin packages update from the Adoptium repository when it stays enabled:
sudo dnf upgrade 'temurin-*'Package updates can refresh alternatives registrations or priorities. After updating systems with multiple JDKs, verify the selected runtime and compiler:
java -version
javac -version
alternatives --display java | head -5Uninstall Java
OpenJDK packages
List installed OpenJDK RPMs with rpm:
rpm -qa | grep openjdkRemove the development and runtime packages you no longer need. Preview the transaction first:
sudo dnf remove --assumeno java-21-openjdk-devel java-21-openjdk java-21-openjdk-headlessReview the dependency list, then run the actual removal:
sudo dnf remove java-21-openjdk-devel java-21-openjdk java-21-openjdk-headlessAfter removal, confirm no stale alternative or profile entry remains:
alternatives --display java
java -versionRemove or update /etc/profile.d/java.sh if it still points at the deleted JDK.
Temurin
sudo dnf remove -y temurin-17-jdk
sudo rm -f /etc/yum.repos.d/adoptium.repo
sudo dnf makecacheOracle tarball
Remove the alternatives entries before you delete the extracted directory:
sudo alternatives --remove java /opt/jdk/jdk-21/bin/java
sudo alternatives --remove javac /opt/jdk/jdk-21/bin/javac
sudo rm -rf /opt/jdk/jdk-21Replace jdk-21 with your exact extracted directory. Delete any /etc/profile.d/java.sh snippet that referenced that path.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
java: command not found |
No JRE/JDK installed or alternatives broken |
Install java-<version>-openjdk-headless; run alternatives --display java |
javac: command not found |
JRE only—no JDK | Install java-<version>-openjdk-devel |
| Wrong Java version after install | Another JDK has higher alternatives priority, or java and javac differ |
Run sudo alternatives --config java and sudo alternatives --config javac; verify both with java -version and javac -version |
JAVA_HOME unset in builds |
Shell or service lacks export | Set /etc/profile.d/java.sh for login shells; set Environment= or EnvironmentFile= on systemd units |
Temurin dnf 404 on Rocky/Alma |
Wrong Adoptium baseurl distribution segment |
Check Adoptium current repository tree and supported-platform list; on the tested Rocky Linux 10.2 host, replacing the rocky segment with rhel resolved the repository |
No matching Packages to list for Java 17 on EL10 |
Major not in distribution repositories on the tested host | Install temurin-17-jdk from Adoptium instead |
| GUI Java apps fail on headless server | Headless JRE missing AWT peers | Install full java-<version>-openjdk or required font/GUI deps |
Summary
Install Java on RHEL-family Linux with sudo dnf install java-<version>-openjdk-devel when your distribution repositories ship your target major. Use java-<version>-openjdk-headless for runtime-only hosts when you are certain no compiler is required. Add Eclipse Temurin from Adoptium when the distribution lacks the version you need, or install Oracle JDK from a tarball when your organization requires it. Switch defaults with alternatives for both java and javac, set JAVA_HOME for login shells and systemd separately, verify with java -version and a javac compile test, and preview package removal with dnf remove --assumeno before you uninstall.
Official references:
- OpenJDK install guide
- Adoptium Linux installation
- Red Hat OpenJDK documentation
- Oracle Java downloads.

