Installing Java on Fedora: only OpenJDK 25 ships, so what about 21 or 17
The trap first: Fedora 45 has no Java 21 and no Java 17 in its repositories.
What the repositories actually contain
Section titled “What the repositories actually contain”dnf list --available 'java-*-openjdk.x86_64'java-25-openjdk.x86_64 1:25.0.4.1.1-1.1.fc45java-latest-openjdk.x86_64 1:27.0.0.0.35-0.0.1.0.ea.fc45Only two: 25 (the current LTS) and java-latest (a 27 early-access build).
This is not a broken repo. Compare three generations:
| Release | JDKs offered |
|---|---|
| F43 | java-21, java-25, java-latest |
| F44 | java-25, java-latest |
| F45 | java-25, java-latest |
Java 21 was removed in F44. So dnf install java-21-openjdk from an old tutorial ends in No match for argument.
Install JDK 25
Section titled “Install JDK 25”sudo dnf install java-25-openjdkFor server-side programs only, the smaller headless build is enough:
sudo dnf install java-25-openjdk-headlessVerify:
java -versionopenjdk version "25.0.4.1" 2026-08-18OpenJDK Runtime Environment (Red_Hat-25.0.4.1.1-1) (build 25.0.4.1+1)OpenJDK 64-Bit Server VM (Red_Hat-25.0.4.1.1-1) (build 25.0.4.1+1, mixed mode, sharing)Where it landed:
readlink -f "$(command -v java)"java -XshowSettings:properties -version 2>&1 | grep java.home/usr/lib/jvm/java-25-openjdk/bin/java java.home = /usr/lib/jvm/java-25-openjdkSetting JAVA_HOME
Section titled “Setting JAVA_HOME”Many build tools (Maven, Gradle, Tomcat) require JAVA_HOME, and Fedora does not set it:
echo $JAVA_HOME # emptyPut it in a profile script:
sudo tee /etc/profile.d/java.sh >/dev/null <<'EOF'export JAVA_HOME=/usr/lib/jvm/java-25-openjdkexport PATH=$JAVA_HOME/bin:$PATHEOFsource /etc/profile.d/java.shecho $JAVA_HOMEA minimal program
Section titled “A minimal program”cat > Hello.java <<'EOF'public class Hello { public static void main(String[] args) { System.out.println("Java " + System.getProperty("java.version")); }}EOFjava Hello.javaSince JDK 11, single-file source execution means no separate javac step:
Java 25.0.4.1If you need Java 21 or 17
Section titled “If you need Java 21 or 17”The repositories have neither, so there are three routes.
1. Containers (least friction)
Section titled “1. Containers (least friction)”podman run --rm eclipse-temurin:21-jdk java -versionThe application runs in the container; the host needs no old JDK. This is also the direction Fedora recommends.
2. Upstream tarball (when the JDK must be on the host)
Section titled “2. Upstream tarball (when the JDK must be on the host)”mkdir -p ~/jdk && cd ~/jdkcurl -LO https://github.com/adoptium/temurin21-binaries/releases/latest/download/OpenJDK21U-jdk_x64_linux_hotspot.tar.gztar xzf OpenJDK21U-jdk_x64_linux_hotspot.tar.gzexport JAVA_HOME=~/jdk/jdk-21*$JAVA_HOME/bin/java -version3. SDKMAN (several versions on a dev machine)
Section titled “3. SDKMAN (several versions on a dev machine)”curl -s "https://get.sdkman.io" | bashsource ~/.sdkman/bin/sdkman-init.shsdk install java 21.0.5-temsdk use java 21.0.5-temBest when you need to switch between 17/21/25 frequently.
Common traps
Section titled “Common traps”| Symptom | Cause |
|---|---|
No match for argument: java-21-openjdk | removed since F44 — not a repo problem |
JAVA_HOME is empty | Fedora does not set it; write a profile script |
java not found after installing | only -headless installed without JRE, or PATH missing $JAVA_HOME/bin |
| wrong version with two JDKs present | use update-alternatives --config java or change JAVA_HOME |
Related pages
Section titled “Related pages”- Toolchain and multiple versions — the general strategy on Fedora
- Containers and rootless — isolating an old JDK
- Module streams (retired) — why “switch the stream” is gone
- Fedora repositories and dnf5 — package basics
- Official: Java