How To Install Java 8 On Linux: A Complete Step-By-Step Guide

You Need Java 8 for That Legacy Application

You’ve just cloned a repository, or you’re trying to run a critical internal tool, and the error message hits you: “UnsupportedClassVersionError” or “Java 1.8 required.” Despite newer versions like Java 11, 17, and 21 being available, a vast ecosystem of software, from big data tools like Apache Spark to legacy enterprise applications, still depends on Java 8. If you’re on a Linux system, getting the right version installed and configured is your next hurdle.

This guide walks you through the most reliable methods to install Java 8 on major Linux distributions. We’ll cover official package managers, manual installation from Oracle or OpenJDK, and crucially, how to manage multiple Java versions side-by-side so your system remains stable.

Understanding Your Java 8 Options

Before you run any commands, it’s important to know what “Java 8” means in the Linux world. You primarily have two choices: OpenJDK 8 and Oracle Java 8. OpenJDK is the open-source reference implementation and is freely available in most distribution repositories. Oracle Java 8 requires manual download and may have different license terms for commercial use. For most development and general purposes, OpenJDK 8 is the recommended and simplest path.

Your installation method will also depend on your Linux distribution. Package managers like apt for Debian/Ubuntu and yum or dnf for Red Hat-based systems (Fedora, CentOS, RHEL) make installation a one-command affair. We’ll start there.

Installing OpenJDK 8 on Ubuntu and Debian

For systems using the apt package manager, the process is straightforward. First, update your local package index to ensure you get the latest available version.

Open your terminal and run:

sudo apt update

Once the update completes, you can search for the available OpenJDK 8 packages.

apt search openjdk-8

You will likely see packages like openjdk-8-jdk (the full Java Development Kit) and openjdk-8-jre (the Java Runtime Environment, if you only need to run applications). To install the JDK, which includes the compiler and tools most users need, execute:

sudo apt install openjdk-8-jdk

The package manager will handle all dependencies. After installation, verify it by checking the Java version.

java -version

You should see output similar to “openjdk version 1.8.0_412.” Congratulations, Java 8 is now installed.

Installing OpenJDK 8 on Fedora, CentOS, and RHEL

On Red Hat-based systems, you’ll use the dnf command (or yum on older CentOS versions). The package names are slightly different. Begin by updating your system’s repository metadata.

For dnf:

sudo dnf update

Then, search for the appropriate Java 8 package.

dnf search java-1.8.0

Look for packages named java-1.8.0-openjdk (the JRE) or java-1.8.0-openjdk-devel (the JDK). To install the development kit, run:

how to install java 8 on linux
sudo dnf install java-1.8.0-openjdk-devel

If you’re on an older CentOS system using yum, the command is nearly identical.

sudo yum install java-1.8.0-openjdk-devel

After the installation finishes, run the verification command to confirm.

java -version

When the Package Manager Doesn’t Have It

Some newer or minimalist Linux distributions may not include Java 8 in their default repositories, as maintainers focus on supporting current Long-Term Support versions. If apt or dnf reports “Unable to locate package,” you have two main alternatives: adding a dedicated repository or performing a manual installation.

Adding the Ubuntu Java 8 Repository (PPA)

For Ubuntu users, a popular and trusted method is to use a Personal Package Archive (PPA). The “openjdk-r” PPA often maintains older Java versions. You can add it to your system and install from there.

First, install the software-properties-common package if you don’t have it, which provides the add-apt-repository command.

sudo apt install software-properties-common

Next, add the PPA for OpenJDK.

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt update

Now, you can install OpenJDK 8 as before.

sudo apt install openjdk-8-jdk

This method typically provides a well-integrated package that receives security updates.

Manual Installation from Oracle or OpenJDK

A manual installation gives you maximum control over the version and installation path, which is useful for system-wide deployments or when you need multiple JDK versions. You’ll download a compressed archive (.tar.gz) and extract it to a directory like /usr/lib/jvm or /opt.

First, navigate to a directory where you can download files, such as /tmp.

cd /tmp

For OpenJDK, visit the official Adoptium website (formerly AdoptOpenJDK) or use wget to download a build. For Oracle Java 8, you would need to visit the Oracle Java Archive website, accept the license agreement, and get the download link. Here’s an example using wget for an OpenJDK 8 build (note: the exact URL may change; check the site for the latest).

wget https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u412-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u412b08.tar.gz

Create a directory for Java if it doesn’t exist.

sudo mkdir -p /usr/lib/jvm

Extract the downloaded archive into this directory.

how to install java 8 on linux
sudo tar -xzf OpenJDK8U-jdk_x64_linux_hotspot_8u412b08.tar.gz -C /usr/lib/jvm

This creates a folder like /usr/lib/jvm/jdk8u412-b08. The final, critical step is to tell your system about this new Java installation.

Configuring Java Alternatives on Your System

Linux systems often have multiple Java versions installed. The update-alternatives command is the standard tool for managing which version is the default when you run java or javac from the command line. This is essential after a manual install or when you have both Java 8 and a newer version like Java 17.

To register your manually installed Java 8 with update-alternatives, you need to add it for both the java and javac commands. Use the following commands, adjusting the path to match your extracted directory.

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk8u412-b08/bin/java 2
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk8u412-b08/bin/javac 2

The number “2” at the end is a priority. Higher numbers have higher priority if set to auto mode. Now, to switch between installed Java versions, you can use the –config option.

sudo update-alternatives --config java

This command presents a numbered menu of all registered Java installations. Simply type the selection number corresponding to your Java 8 installation and press Enter. Repeat the process for javac if needed.

sudo update-alternatives --config javac

After configuration, verify that both java -version and javac -version point to your Java 8 installation.

Setting the JAVA_HOME Environment Variable

Many applications and build tools like Maven, Gradle, and Tomcat rely on the JAVA_HOME environment variable to locate the JDK. It should point to the root directory of your Java installation, not the bin folder.

You can set it temporarily for your current shell session.

export JAVA_HOME=/usr/lib/jvm/jdk8u412-b08
export PATH=$JAVA_HOME/bin:$PATH

To make this permanent for all users, a common approach is to create a shell script in the /etc/profile.d/ directory. This ensures it’s loaded at login.

sudo nano /etc/profile.d/java8.sh

Add the following lines to the file, again using your correct path.

export JAVA_HOME=/usr/lib/jvm/jdk8u412-b08
export PATH=$JAVA_HOME/bin:$PATH

Save the file and exit the editor. To apply the changes to your current session without logging out, source the script.

source /etc/profile.d/java8.sh

You can verify JAVA_HOME is set correctly.

echo $JAVA_HOME

Troubleshooting Common Installation Issues

Even with a clear guide, you might encounter snags. Here are solutions to frequent problems.

how to install java 8 on linux

Verification Command Shows the Wrong Version

If java -version still shows an older or newer Java version after installation, the update-alternatives configuration is likely incorrect. Run sudo update-alternatives –config java and ensure you select the correct entry. Also, check if another Java directory appears earlier in your system’s PATH variable by running echo $PATH.

Permission Denied Errors

When manually installing to /usr/lib/jvm, ensure the directories and files have the correct ownership. The extracted files should be owned by root. If you encounter permission issues, you can recursively change the ownership.

sudo chown -R root:root /usr/lib/jvm/jdk8u412-b08

SSL Certificate Errors with wget

If downloading from Oracle’s website with wget fails due to certificate issues, you can bypass the check (not recommended for sensitive operations) or use curl instead. Often, visiting the Oracle site in a browser, accepting the license, and copying the download link for use with wget is the most reliable method.

Application Still Complains About Java Version

Some applications, especially those launched from a desktop icon or a system service, may not read the JAVA_HOME variable from your shell profile. For these, you may need to set the environment variable directly in the application’s startup script or systemd service file. Check the application’s documentation for specifics.

Managing Multiple Java Versions Effectively

Professional developers often need to switch between Java versions for different projects. While update-alternatives works, tools like SDKMAN! provide a more elegant solution. SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits, including Java.

To install SDKMAN!, run:

curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"

Once installed, you can list available Java versions.

sdk list java

To install a specific OpenJDK 8 version, use its identifier from the list.

sdk install java 8.0.412-tem

Switching becomes a single command.

sdk use java 8.0.412-tem

This tool isolates versions per shell session or project, preventing system-wide conflicts and simplifying your workflow immensely.

Your Linux System Is Now Ready for Java 8

Whether you used the simplicity of a package manager, the control of a manual install, or the power of SDKMAN!, you now have a working Java 8 environment. The key to a smooth experience is proper configuration—ensuring the system’s default points to the correct version and that JAVA_HOME is set for your tools.

Your next step is to test the installation with the application that required it. Run your build script or start your server. If issues persist, double-check the specific version requirements; some older software might need an early update of Java 8 (like 8u191) due to later API changes. With Java 8 installed and configured, you’ve unlocked compatibility with a significant portion of the software world, allowing you to maintain, develop, and run the tools you depend on.

Leave a Comment

close