Fedora 42 ships three OpenJDK versions in its default repositories: Java 21 (LTS), Java 25, and Java 26 (rolling release). You can install any of them with a single dnf command, run them side by side, and switch between versions using alternatives. No PPAs, no third-party repos, no manual downloads.
This guide covers installing OpenJDK on Fedora 42 and 41, switching between multiple versions, setting JAVA_HOME, and verifying your setup works for development. If you are setting up a Java development environment, pair this with our guides on installing NetBeans on Fedora or Apache Maven on Fedora.
Tested March 2026 | Fedora 42 (kernel 6.14.0), OpenJDK 21.0.10, OpenJDK 25.0.2, OpenJDK 26
Available Java Versions on Fedora
Before installing, understand what is available. Fedora maintains multiple OpenJDK versions simultaneously:
| Package | Java Version | Type | Fedora 42 | Fedora 41 |
|---|---|---|---|---|
java-21-openjdk-devel | OpenJDK 21 (LTS) | Long-term support | 21.0.10 | 21.0.6 |
java-25-openjdk-devel | OpenJDK 25 | Current GA release | 25.0.2 | Not available |
java-latest-openjdk-devel | OpenJDK 26 | Rolling (latest) | 26 | 24.x |
For production applications and enterprise frameworks like Spring Boot, Java 21 (LTS) is the safe choice. For experimenting with the newest language features (pattern matching improvements, value classes, Valhalla previews), install java-latest-openjdk-devel.
Install OpenJDK 21 (LTS, Recommended)
Java 21 is the current long-term support release, supported until at least September 2029. Most Java frameworks, build tools, and IDEs target Java 21 as their baseline.
Install the full JDK (includes javac, jshell, jlink, and all development tools):
sudo dnf install -y java-21-openjdk-devel
Verify both the runtime and compiler are available:
java -version
javac -version
The output confirms OpenJDK 21:
openjdk version "21.0.10" 2026-01-20
OpenJDK Runtime Environment (Red_Hat-21.0.10.0.7-2) (build 21.0.10+7)
OpenJDK 64-Bit Server VM (Red_Hat-21.0.10.0.7-2) (build 21.0.10+7, mixed mode, sharing)
javac 21.0.10
If you only need to run Java applications (not compile), install the smaller runtime-only package: sudo dnf install java-21-openjdk. For development, always install the -devel package.
Install OpenJDK 26 (Latest)
The java-latest-openjdk package tracks the newest OpenJDK release. On Fedora 42, this is OpenJDK 26. The version will increment automatically with future Fedora updates.
sudo dnf install -y java-latest-openjdk-devel
Verify:
java -version
On Fedora 42:
openjdk version "26" 2026-03-17
OpenJDK Runtime Environment (Red_Hat-26.0.0.0.35-1) (build 26+35)
OpenJDK 64-Bit Server VM (Red_Hat-26.0.0.0.35-1) (build 26+35, mixed mode, sharing)
Note that java-latest-openjdk has a low alternatives priority (1), so it will not become your default Java unless you explicitly switch to it. This is intentional because the latest release is not always the best choice for production builds.
Install Multiple Versions Side by Side
Fedora supports running multiple JDK versions simultaneously. Install all three at once:
sudo dnf install -y java-21-openjdk-devel java-25-openjdk-devel java-latest-openjdk-devel
Each version installs to its own directory under /usr/lib/jvm/:
ls -d /usr/lib/jvm/java-*
The output shows all installed JDK paths:
/usr/lib/jvm/java-21-openjdk
/usr/lib/jvm/java-25-openjdk
/usr/lib/jvm/java-latest-openjdk
Switch Between Java Versions
Fedora uses the alternatives system to manage which Java version responds when you type java or javac. Check the current default:
alternatives --display java | head -5
This shows the active version and all available options:
java - status is auto.
link currently points to /usr/lib/jvm/java-21-openjdk/bin/java
/usr/lib/jvm/java-21-openjdk/bin/java - priority 21001007
/usr/lib/jvm/java-25-openjdk/bin/java - priority 1
/usr/lib/jvm/java-latest-openjdk/bin/java - priority 1
Java 21 has the highest priority (21001007) so it’s the default in auto mode. To switch to a different version, use alternatives --set:
sudo alternatives --set java /usr/lib/jvm/java-25-openjdk/bin/java
sudo alternatives --set javac /usr/lib/jvm/java-25-openjdk/bin/javac
Confirm the switch:
java -version
Now reports Java 25:
openjdk version "25.0.2" 2026-01-20
OpenJDK Runtime Environment (Red_Hat-25.0.2.0.10-2) (build 25.0.2+10)
OpenJDK 64-Bit Server VM (Red_Hat-25.0.2.0.10-2) (build 25.0.2+10, mixed mode, sharing)
To revert to the default (highest priority version), switch back to auto mode:
sudo alternatives --auto java
sudo alternatives --auto javac
Always set both java and javac together. Setting only one creates a mismatch where the runtime and compiler are different versions, which leads to confusing build errors.
Set JAVA_HOME
Build tools like Maven, Gradle, and Ant use JAVA_HOME to find the JDK. IDEs like NetBeans and IntelliJ also read this variable. Set it in your shell profile so it persists across sessions.
For a specific version (hardcoded):
echo 'export JAVA_HOME=/usr/lib/jvm/java-21-openjdk' | sudo tee /etc/profile.d/java.sh
source /etc/profile.d/java.sh
For a dynamic JAVA_HOME that follows whatever alternatives is set to:
echo 'export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))' | sudo tee /etc/profile.d/java.sh
source /etc/profile.d/java.sh
Verify it is set correctly:
echo $JAVA_HOME
Should output the active JDK path:
/usr/lib/jvm/java-21-openjdk
For a deeper look at JAVA_HOME configuration across RHEL-family systems, see our guide on setting JAVA_HOME on CentOS, Fedora, and RHEL.
Verify Your Java Development Setup
A quick way to confirm everything works is to compile and run a simple program:
cat > /tmp/Hello.java <<'EOF'
public class Hello {
public static void main(String[] args) {
System.out.println("Java " + System.getProperty("java.version") + " on " + System.getProperty("os.name"));
}
}
EOF
javac /tmp/Hello.java -d /tmp/
java -cp /tmp Hello
The output confirms both the compiler and runtime are working:
Java 21.0.10 on Linux
JRE vs JDK: Which Package Do You Need?
Each OpenJDK version has multiple sub-packages. Here is what they contain:
| Package | Contains | Use case |
|---|---|---|
java-21-openjdk-headless | java runtime only, no GUI libs | Servers, containers, CLI tools |
java-21-openjdk | Full JRE with GUI support (AWT, Swing) | Running desktop Java apps |
java-21-openjdk-devel | JDK: javac, jshell, jlink, headers | Java development, IDEs, build tools |
If you are developing Java applications or using tools like Apache Tomcat or Maven, install the -devel package. For running pre-built JARs on a server, -headless is sufficient and keeps the footprint small.
Uninstall a Java Version
Remove a specific version without affecting others:
sudo dnf remove java-25-openjdk-devel java-25-openjdk java-25-openjdk-headless
The alternatives system automatically falls back to the next highest-priority version. Verify with java -version after removal.
Why is java-latest-openjdk not the default?
The java-latest-openjdk package has an alternatives priority of 1 (the lowest possible). Fedora does this intentionally because the rolling release may introduce breaking changes between updates. Java 21 (LTS) gets priority 21001007 because it provides stable API guarantees. If you want the latest version as your default, explicitly set it with alternatives --set java as shown above.
How do I check which Java versions are installed?
List all installed JDK packages:
rpm -qa | grep openjdk-devel
Or see all registered alternatives:
alternatives --display java | grep priority
Can I use a specific Java version for one project without changing the system default?
Yes. Set JAVA_HOME in your project’s build configuration or shell session without touching alternatives. For example, to compile with Java 26 temporarily:
JAVA_HOME=/usr/lib/jvm/java-latest-openjdk /usr/lib/jvm/java-latest-openjdk/bin/javac MyApp.java
Maven and Gradle also respect JAVA_HOME set in the environment or in wrapper scripts, so you can use per-project JDK versions without changing the global setting.