How to Install OpenJDK on Fedora Linux

Last updated Saturday, April 4, 2026 4:28 pm Joshua James 6 min read

Fedora’s current repositories already ship multiple OpenJDK tracks, which helps when one project still pins Java 21 LTS while another wants the current Fedora default JDK or the newest feature release. To install OpenJDK on Fedora without adding third-party repositories, pick the versioned DNF package that matches your workload and let alternatives manage the active java and javac commands.

On Fedora 43, that means OpenJDK 21.0.x, 25.0.x, and java-latest-openjdk, which currently tracks OpenJDK 26. That package mix lets you choose between runtime-only and -devel installs, switch versions cleanly, verify the compiler, set JAVA_HOME, and remove older JDKs when a project no longer needs them.

Install OpenJDK on Fedora

Update Fedora Before Installing OpenJDK

Refresh Fedora’s package metadata before installing a JDK. The -y flag accepts the confirmation prompt automatically.

sudo dnf upgrade --refresh -y

These commands use sudo for package-management tasks that need root privileges. If your account is not configured for administrative access yet, follow the guide on how to add a user to sudoers on Fedora first.

Compare Fedora OpenJDK Packages

Once Fedora is current, pick the Java line your project actually targets instead of installing the newest package by habit. For most readers, that means a versioned -devel package so the runtime and compiler stay on the same major release.

TrackPackage to InstallFedora 43 VersionChoose It When
OpenJDK 25 LTSjava-25-openjdk-devel25.0.xYou want Fedora 43’s default Java line for current development work
OpenJDK 21 LTSjava-21-openjdk-devel21.0.xYour framework, CI pipeline, or vendor certification still targets Java 21
java-latest-openjdkjava-latest-openjdk-devel26.0.xYou are testing the newest feature release and can tolerate major-version jumps over time

Fedora package names differ from Debian and Ubuntu. Install java-25-openjdk-devel or java-21-openjdk-devel here, not openjdk-25-jdk or openjdk-21-jdk.

Start with java-latest-openjdk only when you intentionally want Fedora’s rolling feature-release track. It does not stay pinned to an LTS branch.

After you choose the Java line, match the package flavor to how the system will use Java:

  • -devel packages such as java-25-openjdk-devel include the runtime plus compiler tools like javac, jar, and javadoc; use them for development work and most local test environments.
  • Runtime packages such as java-25-openjdk keep the desktop-capable Java runtime but omit compiler tools; use them when the machine only needs to launch Java applications.
  • -headless packages such as java-25-openjdk-headless skip GUI libraries and keep the runtime leaner; use them on Server or minimal installs, containers, CI runners, and other non-GUI hosts.

Install OpenJDK 25 on Fedora

OpenJDK 25 is the current default Java line on Fedora 43, so it is the safest starting point for most new work on this release.

sudo dnf install java-25-openjdk-devel -y

If you only need to run Java applications, swap the package name to java-25-openjdk or java-25-openjdk-headless. The -devel package already pulls in the matching runtime for you.

Confirm that the Fedora package is installed:

rpm -q java-25-openjdk-devel
java-25-openjdk-devel-25.0.2.0.10-5.fc43.x86_64

Install OpenJDK 21 on Fedora

OpenJDK 21 remains the better fit when a framework, vendor certification, or build target is still pinned to that LTS line.

sudo dnf install java-21-openjdk-devel -y

The same naming pattern applies here too. Use java-21-openjdk for a desktop runtime only, or java-21-openjdk-headless on non-GUI systems.

Check the installed package state with RPM:

rpm -q java-21-openjdk-devel
java-21-openjdk-devel-21.0.10.0.7-2.fc43.x86_64

Install java-latest-openjdk on Fedora

The java-latest-openjdk track follows Fedora’s newest feature release instead of staying pinned to an LTS branch. On Fedora 43, that package currently maps to OpenJDK 26.

sudo dnf install java-latest-openjdk-devel -y

Verify that the package itself is installed before you switch it into place:

rpm -q java-latest-openjdk-devel
java-latest-openjdk-devel-26.0.0.0.35-0.1.fc43.x86_64

Fedora gives java-latest-openjdk a very low alternatives priority, so installing it does not automatically replace OpenJDK 25 as the active java command when both are present. Use the version-switch section below when you want to activate it.

Switch OpenJDK Versions on Fedora

Fedora uses the alternatives system to decide which installed runtime and compiler back /usr/bin/java and /usr/bin/javac. When several JDKs are installed, switch both tools together so the compiler and runtime stay aligned.

List Installed OpenJDK Alternatives on Fedora

Run the interactive selector to see every installed Java runtime and the current default:

sudo alternatives --config java
There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/java-25-openjdk/bin/java
   2           /usr/lib/jvm/java-21-openjdk/bin/java
   3           /usr/lib/jvm/java-latest-openjdk/bin/java

Enter to keep the current selection[+], or type selection number:

The *+ marker shows the active automatic choice. If you only installed one runtime, the selector shows a single entry instead of three.

Switch the OpenJDK Compiler on Fedora

Run the matching selector for javac right after switching java. This matters because javac only exists in the -devel packages, and Fedora can leave the compiler on a different major than the runtime if you mix package types.

sudo alternatives --config javac

Relevant output includes:

There are 3 programs which provide 'javac'.

  Selection    Command
-----------------------------------------------
   1           /usr/lib/jvm/java-latest-openjdk/bin/javac
   2           /usr/lib/jvm/java-21-openjdk/bin/javac
*+ 3           /usr/lib/jvm/java-25-openjdk/bin/javac

Select the same major in both menus. If java --version says 25 but javac --version says 21, this selector is the fix.

Set a Specific OpenJDK Version on Fedora

Use the direct --set form when you already know which major you want and do not need the interactive menu. Run only the pair that matches your target version.

# OpenJDK 25
sudo alternatives --set java /usr/lib/jvm/java-25-openjdk/bin/java
sudo alternatives --set javac /usr/lib/jvm/java-25-openjdk/bin/javac

# 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-latest-openjdk, currently OpenJDK 26 on Fedora 43
sudo alternatives --set java /usr/lib/jvm/java-latest-openjdk/bin/java
sudo alternatives --set javac /usr/lib/jvm/java-latest-openjdk/bin/javac

Check the active runtime and compiler after switching:

java --version
javac --version

Relevant output after each switch includes:

# OpenJDK 25
openjdk 25.0.2 2026-01-20
OpenJDK Runtime Environment (Red_Hat-25.0.2.0.10-3) (build 25.0.2+10)
OpenJDK 64-Bit Server VM (Red_Hat-25.0.2.0.10-3) (build 25.0.2+10, mixed mode, sharing)
javac 25.0.2

# OpenJDK 21
openjdk 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

# java-latest-openjdk
openjdk 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)
javac 26

Return to Fedora’s Automatic OpenJDK Selection

Switch back to Fedora’s automatic priority rules when you no longer want a manual override.

sudo alternatives --auto java
sudo alternatives --auto javac
java --version
javac --version
openjdk 25.0.2 2026-01-20
OpenJDK Runtime Environment (Red_Hat-25.0.2.0.10-3) (build 25.0.2+10)
OpenJDK 64-Bit Server VM (Red_Hat-25.0.2.0.10-3) (build 25.0.2+10, mixed mode, sharing)
javac 25.0.2

Get Started with OpenJDK on Fedora

Once the right Java version is active, confirm that the toolchain can compile and run code instead of stopping at package installation.

Compile and Run a Test Program with OpenJDK on Fedora

Create a small Java source file first. Save it as HelloFedora.java in your current directory.

public class HelloFedora {
    public static void main(String[] args) {
        System.out.println("Hello from Fedora OpenJDK " + System.getProperty("java.version"));
    }
}

Compile the file with javac, then run it with java:

javac HelloFedora.java
java HelloFedora
Hello from Fedora OpenJDK 25.0.2

If you switched to OpenJDK 21 or 26 first, the printed version changes to match that runtime. After this test, you can move into build automation with install Apache Maven on Fedora or set up version control with install Git on Fedora.

Find the Active OpenJDK Path on Fedora

Use the resolved java binary to locate the currently active JDK directory. The which command guide explains how the shell finds that binary, and this resolved path is what build tools usually want for JAVA_HOME.

dirname $(dirname $(readlink -f $(which java)))
/usr/lib/jvm/java-25-openjdk

If Maven, Gradle, an IDE, or an application server complains about JAVA_HOME, follow the guide to set Java environment path in Fedora instead of hardcoding a stale directory by hand.

Troubleshoot OpenJDK Issues on Fedora

Most Fedora OpenJDK problems come down to the wrong package type, the wrong active alternative, or a missing environment variable.

Fix javac Command Not Found on Fedora

If the shell returns javac: command not found, you installed a runtime-only package instead of the full development kit.

sudo dnf install java-25-openjdk-devel -y
javac --version
javac 25.0.2

Swap 25 for 21 or latest if you are targeting a different major.

Fix the Wrong OpenJDK Version on Fedora

If java --version reports the wrong major after installation, another runtime still owns the active alternatives entry.

sudo alternatives --config java
sudo alternatives --config javac
java --version
javac --version

Select the same major in both selectors, then recheck the runtime and compiler versions. This is especially important when OpenJDK 25 and 21 are installed together.

Fix JAVA_HOME Errors on Fedora

Build tools that fail with JAVA_HOME is not set or JAVA_HOME is not defined correctly need the active JDK path exported into your shell or service environment.

dirname $(dirname $(readlink -f $(which java)))

Use that path in your shell profile or follow the full steps to set Java environment path in Fedora when you want a persistent JAVA_HOME configuration.

Update or Remove OpenJDK on Fedora

Update OpenJDK Packages on Fedora

Fedora updates installed OpenJDK packages through the normal DNF workflow, so you do not need a separate repository or vendor updater.

sudo dnf upgrade --refresh -y

Recheck java --version after the upgrade if you want to confirm which major is currently active.

Remove OpenJDK Packages on Fedora

Remove the version you no longer need by targeting its package names directly. This example removes the OpenJDK 21 development kit and its matching runtime packages.

sudo dnf remove java-21-openjdk-devel java-21-openjdk java-21-openjdk-headless -y

Replace 21 with 25 or latest if you are removing a different major. Verify the removal with RPM:

rpm -q java-21-openjdk-devel java-21-openjdk java-21-openjdk-headless
package java-21-openjdk-devel is not installed
package java-21-openjdk is not installed
package java-21-openjdk-headless is not installed

OpenJDK on Fedora FAQ

Which OpenJDK version is Fedora 43 using by default?

Fedora 43 currently defaults to OpenJDK 25 for the active java command. Install java-21-openjdk-devel when you need Java 21 LTS, or java-latest-openjdk-devel when you deliberately want the feature-release track, which currently maps to OpenJDK 26.

Should I install java-latest-openjdk or java-25-openjdk on Fedora?

Install java-25-openjdk or java-25-openjdk-devel when you want Fedora 43’s current stable LTS line to stay pinned on Java 25. Install java-latest-openjdk only when you want Fedora to move you onto the newest feature release as that package changes majors over time.

Why does javac show a different version from java on Fedora?

The java command comes from runtime packages such as java-25-openjdk, while javac only comes from the matching -devel package. If multiple JDKs are installed, switch both with sudo alternatives --config java and sudo alternatives --config javac so the compiler and runtime stay aligned.

Do I need JAVA_HOME on Fedora after installing OpenJDK?

Not for basic command-line use. Tools such as Maven, Gradle, IDEs, and application servers sometimes expect JAVA_HOME, so check the active path with dirname $(dirname $(readlink -f $(which java))) and export it only when the tool specifically asks for it.

Conclusion

OpenJDK is now running on Fedora with the Java line your projects actually need, whether that is 21 LTS, Fedora’s default 25 LTS, or the current 26 feature release. If build automation is next, install Apache Maven on Fedora, and if a framework expects a fixed JDK path, set Java environment path in Fedora.

Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffee Buy me a coffee

Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: