Installing Java 8 (Oracle JDK) on Fedora

📢 This article was translated by gemini-2.5-flash

Intro

Fedora comes with Java, but it’s OpenJDK. Sometimes, you just need Oracle’s version.

Download

Head to the official site to download: Java Downloads | Oracle (Requires login to download)

Find java8-Linux, then grab the x64 Compressed Archive (that’s the 64-bit compressed package).

As of writing, the file was named jdk-8u341-linux-x64.tar.gz.

Move to Directory

  1. First, create a Java directory under /usr/local.
1
sudo mkdir -p /usr/local/java
  1. Copy the file there.

Assuming your download is in ~/Downloads, navigate to it.

1
cd Downloads

Then copy it to the directory we just made.

1
sudo cp -r jdk-8u341-linux-x64.tar.gz /usr/local/java

Extract the Archive

  1. Switch to the Java directory.
1
cd /usr/local/java
  1. Extract the installation file.
1
sudo tar xvzf jdk-8u341-linux-x64.tar.gz

Configure $PATH

  1. Add these lines to the end of /etc/profile.
1
2
3
4
JAVA_HOME=/usr/local/java/jdk1.8.0_341
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH

Update Available Java Versions

  1. Run these commands directly.
1
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_341/bin/java" 1
1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_341/bin/javac" 1
1
sudo update-alternatives --install "/usr/bin/javaws.itweb" "javaws.itweb" "/usr/local/java/jdk1.8.0_341/bin/javaws.itweb" 1

Apply Configuration

  1. First, reload the system-wide PATH file.
1
source /etc/profile
  1. Reboot your system.
1
reboot

Switch Java Version

You can check the current Java version by running:

1
java -version
  1. Use the following command to switch:
1
sudo alternatives --config java

The currently active Java version will have a + next to it. Find your desired version and type its number to select.

References

How to Install Java on Fedora {OpenJDK and Oracle JDK}

This post is licensed under CC BY-NC-SA 4.0 by the author.