Setting the Java environment path on Fedora gives build tools, IDEs, application servers, and shell scripts a reliable JAVA_HOME value. That matters when Maven, Gradle, Tomcat, WildFly, or an editor plugin needs the JDK directory instead of only the java command in /usr/bin.
Current Fedora releases use versioned OpenJDK packages and the alternatives system to manage active Java commands. Fedora 44 and Fedora 43 differ slightly, so check the package table before copying a version-specific command, then set JAVA_HOME on Fedora with the dynamic method when you want the variable to follow the active Java version automatically.
Choose a Fedora Java Package
Install a JDK package before setting JAVA_HOME. The JDK includes javac, jar, and other development tools that many Java workflows expect. If you only run Java applications, the runtime or headless packages may be enough, but development environments usually need the -devel package.
| Need | Package Pattern | Use When |
|---|---|---|
| Full JDK | java-25-openjdk-devel | You compile code, run Maven or Gradle, or need javac. |
| Desktop runtime | java-25-openjdk | You run Java desktop applications but do not compile code. |
| Headless runtime | java-25-openjdk-headless | You run Java services, CI jobs, containers, or server workloads without GUI libraries. |
For a wider OpenJDK package comparison, including runtime-only and headless variants, use the dedicated guide to install OpenJDK on Fedora. Once a JDK is installed, return to the environment path workflow.
Fedora OpenJDK Version Matrix
| Track | Fedora 44 | Fedora 43 | JDK Package | Best Fit |
|---|---|---|---|---|
| OpenJDK 25 | Available | Available | java-25-openjdk-devel | Stable Fedora-packaged JDK for most current development work. |
| OpenJDK 21 | Not in standard Fedora 44 repositories | Available | java-21-openjdk-devel | Fedora 43 projects that still require Java 21. |
| Rolling latest | OpenJDK 26 at the May 2026 refresh | OpenJDK 26 at the May 2026 refresh | java-latest-openjdk-devel | Testing the newest feature release when major-version changes are acceptable. |
Fedora 44 removed java-21-openjdk from its standard repositories as part of the Fedora Java 21 transition. The Fedora Java 21 removal change explains why Fedora moved that maintenance work away from Fedora 44. If a project requires Java 21 on Fedora 44, treat that as a separate vendor-JDK decision instead of forcing the Fedora 43 package command onto a newer release.
Install Java on Fedora
Install only the JDK needed for your JAVA_HOME workflow. If your main task is comparing every Fedora Java package, runtime, and removal variant, use the OpenJDK install guide linked earlier.
Check for Existing Java Commands
Start by checking whether Fedora already has a Java runtime and compiler:
java -version
javac -version
A runtime-only install can provide java while javac is still missing. That is normal on systems with only java-25-openjdk-headless or another runtime package installed.
Install Java 25 on Fedora 44 or Fedora 43
OpenJDK 25 is the versioned Fedora package line to use for most current JDK work:
sudo dnf install java-25-openjdk-devel
Verify the package and compiler after installation:
rpm -q java-25-openjdk-devel
java -version
javac -version
Relevant Fedora 44 output includes the major version and package branch. The exact update number can change after security updates.
java-25-openjdk-devel-25.0.3.0.9-1.fc44.x86_64 openjdk version "25.0.3" 2026-04-21 javac 25.0.3
Install Java 21 on Fedora 43 Only
Use the Java 21 package only on Fedora releases that still publish it. Fedora 43 provides this package, while Fedora 44 does not:
sudo dnf install java-21-openjdk-devel
If Fedora 44 returns a no-match error for that package, do not add --skip-unavailable and continue as if Java 21 was installed. Pick OpenJDK 25 from Fedora’s repositories or use a separate vendor-supported Java 21 workflow.
Install Fedora’s Rolling Latest OpenJDK
The java-latest-openjdk package follows Fedora’s newest feature release. At the May 2026 refresh, that means OpenJDK 26, but the package can move to another major release later:
sudo dnf install java-latest-openjdk-devel
Use this track only when your project tolerates feature-release changes. If you need a stable major version for builds or CI, choose a versioned package such as java-25-openjdk-devel.
Understand JAVA_HOME and PATH on Fedora
JAVA_HOME should point to the JDK root directory, not to the java binary itself. On Fedora, a typical OpenJDK 25 JDK path is /usr/lib/jvm/java-25-openjdk, while the command managed by alternatives is /usr/bin/java.
The alternatives system controls the /usr/bin/java and /usr/bin/javac symlinks. JAVA_HOME does not replace those symlinks by itself. Adding $JAVA_HOME/bin to the front of PATH makes your shell find that JDK’s tools first, but programs that call /usr/bin/java still follow the alternatives selection.
In practical terms, JAVA_HOME affects tools that read that variable, while /usr/bin/java is affected by alternatives and shell PATH order. Keep those three pieces aligned when troubleshooting mixed Java versions.
Find the Active JAVA_HOME Path
Derive JAVA_HOME from the active java command with command -v and readlink -f:
dirname "$(dirname "$(readlink -f "$(command -v java)")")"
For OpenJDK 25 on Fedora, the output should look like this:
/usr/lib/jvm/java-25-openjdk
If the command returns a runtime path and javac is missing, install the matching -devel package before using that path for development tools.
Set JAVA_HOME Temporarily
Use a temporary export when testing whether a tool recognizes the path:
export JAVA_HOME="/usr/lib/jvm/java-25-openjdk"
export PATH="$JAVA_HOME/bin:$PATH"
This setting lasts only for the current shell. Close the terminal and the variable disappears.
Set JAVA_HOME Permanently
Choose the permanent method based on scope. Dynamic methods follow the active alternatives-selected Java command. Static methods stay pinned to one directory until you edit them again.
| Method | Scope | Tracks Alternatives | Use When |
|---|---|---|---|
/etc/profile.d/ dynamic script | System-wide shell logins | Yes | Most Fedora workstations and shared development machines. |
~/.bashrc dynamic block | One user | Yes | Only your account needs JAVA_HOME. |
~/.bashrc static exports | One user | No | A project must stay on one JDK regardless of alternatives. |
/etc/environment static entry | System-wide PAM login environment | No | Simple server setups with one fixed JDK path. |
Method 1: System-Wide Dynamic JAVA_HOME
Create a profile script when every shell login should receive the active Fedora Java path:
sudo tee /etc/profile.d/java-home.sh > /dev/null <<'EOF'
if command -v java >/dev/null 2>&1; then
JAVA_HOME=$(dirname "$(dirname "$(readlink -f "$(command -v java)")")")
export JAVA_HOME
case ":$PATH:" in
*":$JAVA_HOME/bin:"*) ;;
*) export PATH="$JAVA_HOME/bin:$PATH" ;;
esac
fi
EOF
The script does nothing when Java is not installed, which prevents login errors after removing Java. The PATH check also avoids adding the same JDK directory again when the script is sourced more than once.
Load the script in the current shell, or open a new terminal:
source /etc/profile.d/java-home.sh
Method 2: User-Specific Dynamic JAVA_HOME
Use the same logic in ~/.bashrc when only your user account needs the Java environment variable:
nano ~/.bashrc
Add this block near the end of the file after removing any older duplicate JAVA_HOME exports:
if command -v java >/dev/null 2>&1; then
JAVA_HOME=$(dirname "$(dirname "$(readlink -f "$(command -v java)")")")
export JAVA_HOME
case ":$PATH:" in
*":$JAVA_HOME/bin:"*) ;;
*) export PATH="$JAVA_HOME/bin:$PATH" ;;
esac
fi
Apply the change to the current shell:
source ~/.bashrc
Method 3: User-Specific Static JAVA_HOME
Use a static path only when the account should keep one JDK even if the system alternatives selection changes:
nano ~/.bashrc
Add the path for the JDK you want to pin. This example uses OpenJDK 25:
export JAVA_HOME="/usr/lib/jvm/java-25-openjdk"
export PATH="$JAVA_HOME/bin:$PATH"
For Fedora’s rolling latest package, use /usr/lib/jvm/java-latest-openjdk. For Fedora 43 Java 21, use /usr/lib/jvm/java-21-openjdk. Do not use the Java 21 path on Fedora 44 unless you installed a separate JDK that actually provides it.
Method 4: System-Wide Static JAVA_HOME
The /etc/environment file uses simple NAME="value" entries and is read during login by PAM. It is useful for a fixed system-wide variable, but it cannot run shell logic.
sudo nano /etc/environment
Add the variable without export:
JAVA_HOME="/usr/lib/jvm/java-25-openjdk"
Do not write
export JAVA_HOME=...in/etc/environment. That file is parsed as environment assignments, not executed as a shell script.
If you also need $JAVA_HOME/bin in shell PATH, keep that logic in a profile script instead of trying to expand variables inside /etc/environment.
Switch or Change Java Versions with Alternatives
When multiple JDKs are installed, switch both the runtime and compiler so java and javac stay on the same major version.
View Available Java Alternatives
alternatives --display java
alternatives --display javac
Relevant output on Fedora 44 with OpenJDK 25 and java-latest-openjdk installed shows OpenJDK 25 with a higher priority and java-latest-openjdk with priority 1:
java - status is auto. link currently points to /usr/lib/jvm/java-25-openjdk/bin/java /usr/lib/jvm/java-25-openjdk/bin/java - priority 25000309 /usr/lib/jvm/java-latest-openjdk/bin/java - priority 1
Switch Java Interactively
Use the interactive menus when you want Fedora to show every installed choice:
sudo alternatives --config java
sudo alternatives --config javac
Select matching entries for the same JDK. After switching, source your dynamic JAVA_HOME script or open a new terminal so the environment variable follows the new active command.
Switch Java Directly
Set OpenJDK 25 directly with matching java and javac paths:
sudo alternatives --set java /usr/lib/jvm/java-25-openjdk/bin/java
sudo alternatives --set javac /usr/lib/jvm/java-25-openjdk/bin/javac
Set Fedora’s rolling latest OpenJDK when you installed that package intentionally:
sudo alternatives --set java /usr/lib/jvm/java-latest-openjdk/bin/java
sudo alternatives --set javac /usr/lib/jvm/java-latest-openjdk/bin/javac
On Fedora 43 systems with Java 21 installed, the direct paths use /usr/lib/jvm/java-21-openjdk/bin/java and /usr/lib/jvm/java-21-openjdk/bin/javac.
Return Java to Automatic Selection
sudo alternatives --auto java
sudo alternatives --auto javac
Auto mode chooses the highest-priority installed entry. On Fedora 44 with OpenJDK 25 and java-latest-openjdk installed, that returns the active commands to OpenJDK 25.
Verify JAVA_HOME Configuration
Check the variable, confirm the directory exists, and verify that the selected JDK can run Java through JAVA_HOME:
printf '%s\n' "$JAVA_HOME"
test -x "$JAVA_HOME/bin/java" && "$JAVA_HOME/bin/java" -version
test -x "$JAVA_HOME/bin/javac" && "$JAVA_HOME/bin/javac" -version
Relevant OpenJDK 25 output includes:
/usr/lib/jvm/java-25-openjdk openjdk version "25.0.3" 2026-04-21 javac 25.0.3
If you installed a runtime-only package, the javac test will not print a compiler version. Install the matching -devel package when the workflow needs a compiler.
Update or Remove Java Configuration
Update Fedora Java Packages
Fedora updates OpenJDK through normal DNF transactions:
sudo dnf upgrade --refresh
After a JDK update, confirm the active runtime and compiler still match:
java -version
javac -version
printf '%s\n' "$JAVA_HOME"
Remove User-Specific JAVA_HOME Lines
Edit ~/.bashrc and remove the JAVA_HOME block or static export lines you added:
nano ~/.bashrc
Reload the shell configuration after saving:
source ~/.bashrc
Remove System-Wide JAVA_HOME Files
List the profile scripts before deleting them:
ls -l /etc/profile.d/java-home.sh /etc/profile.d/java-path.sh 2>/dev/null
Remove only the Java environment files you created:
sudo rm -f /etc/profile.d/java-home.sh /etc/profile.d/java-path.sh
If you used /etc/environment, edit the file and remove only the JAVA_HOME=... line:
sudo nano /etc/environment
Remove Fedora OpenJDK Packages
Check which Fedora OpenJDK packages are installed before removing anything:
rpm -qa 'java-*openjdk*' | sort
Removing all OpenJDK runtime packages can also remove Java-dependent applications. Desktop and office packages may appear in the transaction if they depend on a Java runtime, so preview broad removals before confirming them.
Remove only the JDK compiler package you installed when you no longer need development tools. This keeps the runtime available for applications that still depend on Java:
sudo dnf remove java-25-openjdk-devel
If you installed Fedora’s rolling latest JDK, remove its compiler package the same way:
sudo dnf remove java-latest-openjdk-devel
On Fedora 43, remove the Java 21 JDK package only if you installed it:
sudo dnf remove java-21-openjdk-devel
To remove every Fedora OpenJDK runtime and compiler package, preview the transaction first:
sudo dnf remove 'java-*openjdk*' --assumeno
If the preview lists only packages you intentionally want to remove, rerun the command without --assumeno:
sudo dnf remove 'java-*openjdk*'
After removal, verify the remaining Fedora OpenJDK package state:
rpm -qa 'java-*openjdk*' | sort
No output means the Fedora OpenJDK packages matched by that query are gone. If DNF lists orphaned dependencies afterward, run sudo dnf autoremove only after reviewing the proposed transaction.
Troubleshoot JAVA_HOME on Fedora
JAVA_HOME Is Empty in a New Terminal
Check the current value first:
printf '%s\n' "$JAVA_HOME"
If the output is blank, the shell did not load your configuration. For the system-wide profile method, source the profile script:
source /etc/profile.d/java-home.sh
For the user-specific ~/.bashrc method, reload your shell profile instead:
source ~/.bashrc
For /etc/environment, log out and back in because PAM reads that file during login.
javac: command not found
bash: javac: command not found
This means the compiler is missing or not selected, even if the runtime command works. Install the matching JDK package and recheck both commands:
sudo dnf install java-25-openjdk-devel
java -version
javac -version
If several JDKs are installed, also switch javac with alternatives so it matches java.
No Match for java-21-openjdk-devel on Fedora 44
Failed to resolve the transaction: No match for argument: java-21-openjdk-devel
Fedora 44 does not publish java-21-openjdk-devel in its standard repositories. Confirm the available JDK package names, then choose a branch that exists for your Fedora release:
dnf repoquery --available 'java-*-openjdk-devel'
On Fedora 44, use java-25-openjdk-devel for the versioned LTS JDK or java-latest-openjdk-devel for Fedora’s rolling latest feature release.
Cannot Find a J2SE SDK Installed at Path
Cannot find a J2SE SDK installed at path
This older error usually means a tool is reading a stale JAVA_HOME path or finding a runtime without compiler tools. Confirm that the path exists and contains javac:
printf '%s\n' "$JAVA_HOME"
test -x "$JAVA_HOME/bin/javac" && "$JAVA_HOME/bin/javac" -version
If the test fails, install the matching -devel package or update JAVA_HOME to the active JDK path from readlink -f.
JAVA_HOME Points to One Version but java Uses Another
Compare the environment path with the active alternatives path:
printf '%s\n' "$JAVA_HOME"
readlink -f "$(command -v java)"
If they do not match, you probably used a static JAVA_HOME export or changed alternatives after opening the shell. Use the dynamic profile method, or update the static path manually and reload the shell.
export Breaks /etc/environment
export JAVA_HOME="/usr/lib/jvm/java-25-openjdk"
Remove the export keyword from /etc/environment. The correct format is:
JAVA_HOME="/usr/lib/jvm/java-25-openjdk"
Keep shell expressions, command substitutions, and PATH edits in ~/.bashrc or /etc/profile.d/*.sh instead.
Conclusion
A working Fedora Java environment starts with the right OpenJDK package, then keeps JAVA_HOME, PATH, java, and javac aligned. The dynamic /etc/profile.d/ method is the best default because it follows alternatives after version switches, while static exports fit projects that must stay pinned to one JDK. After the path is stable, the same setup helps when configuring tools such as Apache Maven on Fedora.


Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed in published comments:
<code>command</code>command<strong>bold</strong><em>italic</em><a href="https://example.com">link</a><blockquote>quote</blockquote>