How to Install OpenJDK 8 on Ubuntu 26.04, 24.04 and 22.04

Install OpenJDK 8 on Ubuntu 26.04, 24.04 and 22.04 using APT. Covers JRE vs JDK, verification, version switching, removal.

Last updatedAuthorJoshua JamesRead time6 minGuide typeUbuntu

Some legacy Java applications still need Java 8 bytecode, older TLS defaults, or framework versions that cannot move to a newer LTS line yet. If that is your constraint, you can install OpenJDK 8 on Ubuntu from the Ubuntu archive instead of downloading a separate vendor tarball or adding a PPA.

OpenJDK 8 packages are available from the universe component on Ubuntu 26.04 (resolute), 24.04 (noble), and 22.04 (jammy). That package set gives you the runtime, full JDK, alternatives integration, and a package-managed removal path without leaving Ubuntu’s APT workflow.

Install OpenJDK 8 on Ubuntu

Start by refreshing your package index and applying available package updates. This reduces the chance of dependency mismatches before installing Java:

sudo apt update
sudo apt upgrade

These commands use sudo for administrative tasks. If your account cannot run sudo commands yet, add the user to sudoers first with the Ubuntu guide on adding a new user to sudoers on Ubuntu.

Confirm OpenJDK 8 Package Availability

Check the package candidates before installing, especially on minimal systems where the universe component may be disabled:

apt-cache policy openjdk-8-jdk openjdk-8-jre

On Ubuntu 26.04, relevant output includes the current OpenJDK 8 package candidate from resolute/universe. Your mirror hostname may differ:

openjdk-8-jdk:
  Installed: (none)
  Candidate: 8u482-ga~us1-0ubuntu1
  Version table:
     8u482-ga~us1-0ubuntu1 500
        500 http://au.archive.ubuntu.com/ubuntu resolute/universe amd64 Packages
openjdk-8-jre:
  Installed: (none)
  Candidate: 8u482-ga~us1-0ubuntu1

Current package candidates differ slightly by Ubuntu release because Ubuntu appends release-specific suffixes on older LTS versions:

Ubuntu releaseCodenameOpenJDK 8 candidateArchive component
Ubuntu 26.04 LTSresolute8u482-ga~us1-0ubuntu1universe
Ubuntu 24.04 LTSnoble8u482-ga~us1-0ubuntu1~24.04noble-updates/universe, noble-security/universe
Ubuntu 22.04 LTSjammy8u482-ga~us1-0ubuntu1~22.04jammy-updates/universe, jammy-security/universe

If the candidate shows (none) or APT returns Unable to locate package openjdk-8-jdk, enable universe and refresh package metadata. Only universe is required for OpenJDK 8, but the Ubuntu repository guide explains the broader component layout if you need more context on enabling Universe and Multiverse on Ubuntu.

Minimal systems may need software-properties-common before the add-apt-repository helper is available. This package comes from Ubuntu’s main component on supported releases:

sudo apt install software-properties-common
sudo add-apt-repository universe
sudo apt update

Although many readers search for an OpenJDK 8 Linux download, this Ubuntu workflow uses signed APT packages from Ubuntu’s archive. Manual vendor downloads are only useful when a project specifically requires a vendor build such as Temurin, Corretto, or another certified distribution.

Choose the OpenJDK 8 Package

Install one package path that matches your workload. The JDK package pulls in the runtime automatically, so you do not need to install both the JRE and JDK unless you are repairing a partial installation.

PackageUse it when
openjdk-8-jre-headlessYou need Java 8 on Ubuntu Server, containers, or minimal systems without desktop integration.
openjdk-8-jreYou only run Java applications and want the normal runtime package.
openjdk-8-jdkYou compile Java code or use build tools that need javac, headers, and development utilities.

For a headless server, container, or minimal runtime-only install, use the headless JRE package:

sudo apt install openjdk-8-jre-headless

For a desktop runtime without compiler tools, install the standard JRE package:

sudo apt install openjdk-8-jre

For most development systems, install the full JDK:

sudo apt install openjdk-8-jdk

If you found older instructions using apt-get, the package target is the same. For example, sudo apt-get install openjdk-8-jre installs the same JRE package as the apt command above; this article uses apt for the current Ubuntu command style.

Verify OpenJDK 8 on Ubuntu

Check the active Java runtime after installation. OpenJDK 8 uses the single-hyphen -version flag:

java -version

Expected output on the current Ubuntu 26.04 package looks like this. Ubuntu 24.04 and 22.04 append their release suffixes to the runtime build line:

openjdk version "1.8.0_482"
OpenJDK Runtime Environment (build 1.8.0_482-8u482-ga~us1-0ubuntu1-b08)
OpenJDK 64-Bit Server VM (build 25.482-b08, mixed mode)

If you installed the JDK, verify the compiler too:

javac -version
javac 1.8.0_482

Test OpenJDK 8 with a Java Program

A quick compile-and-run test confirms that both the runtime and compiler are working from the same Java 8 installation.

Create a small Java source file:

cat <<'EOF' > Hello.java
public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello from LinuxCapable!");
    }
}
EOF

Compile the source file, then run the compiled class:

javac Hello.java
java Hello
Hello from LinuxCapable!

Remove the temporary test files when you are finished:

rm -f Hello.java Hello.class

Manage Multiple Java Versions

Ubuntu registers Java runtimes and compilers with update-alternatives. If OpenJDK 8 is your only Java installation, the alternatives system already points to it. If you also install OpenJDK 17, 21, 25, or another Java version, use the commands below to choose the active default.

Inspect the Active Java Runtime

Display the current runtime alternative and its registered path. Relevant output includes the active target:

update-alternatives --display java
java - auto mode
  link best version is /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
  link currently points to /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
  link java is /usr/bin/java

When more than one Java runtime is installed, choose the default runtime interactively:

sudo update-alternatives --config java

Select the OpenJDK 8 path, then rerun java -version to confirm the active runtime changed.

Switch the Java Compiler

The Java compiler uses a separate alternatives entry. If your runtime and compiler need to stay on Java 8, configure javac after changing java:

sudo update-alternatives --config javac

A mismatch between java and javac is a common cause of build errors when source code is compiled for one Java release and run with another.

Set JAVA_HOME for OpenJDK 8

If your workflow needs Maven, use the Ubuntu guide for installing Apache Maven on Ubuntu. Gradle and similar build tools also look for JAVA_HOME. For a JDK installation, use the JDK root, not the nested JRE path:

dirname "$(dirname "$(readlink -f "$(command -v javac)")")"
/usr/lib/jvm/java-8-openjdk-amd64

If you installed only the JRE, the runtime path includes /jre:

dirname "$(dirname "$(readlink -f "$(command -v java)")")"
/usr/lib/jvm/java-8-openjdk-amd64/jre

For persistent shell setup, use the dedicated Ubuntu walkthrough for setting the Java environment path on Ubuntu instead of editing profile files by hand in several places.

Compare OpenJDK LTS Releases for Ubuntu

OpenJDK 8 is still a compatibility release for legacy workloads, not the best baseline for new projects. The table below compares common LTS lines and uses the Adoptium Temurin support roadmap for upstream availability windows.

Java optionAdoptium availabilityChoose it whenTrade-offs
OpenJDK 8 on UbuntuAt least Dec 2030Legacy applications, older Spring 4.x stacks, Ant-era builds, or vendor-certified deployments that require Java 8.Missing modern language features such as records, sealed classes, and virtual threads. Some current libraries have already dropped Java 8 support.
Install OpenJDK 11 on UbuntuAt least Oct 2027Older enterprise applications and Spring Boot 2.x stacks that already moved beyond Java 8.Lacks newer Java 17+ framework baselines and language features.
Install OpenJDK 17 on UbuntuAt least Oct 2027Spring Boot 3.x, Jakarta EE 10+, and applications that need a mature modern LTS line.Does not include Java 21 virtual threads or newer LTS features.
Install OpenJDK 21 on UbuntuAt least Dec 2029Current long-lived projects that want virtual threads and a broad Java 21 ecosystem.Older enterprise stacks may not be certified for it yet.
Install OpenJDK 25 on UbuntuAt least Sep 2031New projects that can target the newest LTS release and its finalized language/runtime features.Verify framework and vendor support before moving production workloads.

Use OpenJDK 8 only when the application, build pipeline, or vendor support matrix requires it. For new Java development on Ubuntu, start with OpenJDK 21 or OpenJDK 25 unless your framework specifically recommends a different LTS line.

Troubleshoot OpenJDK 8 on Ubuntu

Unable to Locate openjdk-8-jdk

This error usually means APT has stale package metadata or the universe component is disabled. Confirm the candidate first:

apt-cache policy openjdk-8-jdk

If Candidate: shows (none), enable universe, refresh APT, and retry the install command:

sudo apt install software-properties-common
sudo add-apt-repository universe
sudo apt update
sudo apt install openjdk-8-jdk

java: command not found

If java is still missing after installation, check whether the OpenJDK 8 packages are installed and whether alternatives registered the runtime:

apt-cache policy openjdk-8-jdk openjdk-8-jre
update-alternatives --display java

If the package is installed but no runtime alternative appears, reinstall the JDK package:

sudo apt install --reinstall openjdk-8-jdk

Version Mismatch Between java and javac

Errors such as class file has wrong version or unsupported class file major version often mean java and javac point to different Java releases. Check both versions:

java -version
javac -version

If the versions differ, switch both alternatives to OpenJDK 8:

sudo update-alternatives --config java
sudo update-alternatives --config javac

Could Not Find or Load Main Class

This error usually comes from running the class from the wrong directory or including the .class extension in the command. Check that the compiled file exists, then run the class name without the extension:

ls -l Hello.class
java Hello

If your class belongs to a Java package, run it from the package root with the fully qualified class name.

JAVA_HOME Points to the Wrong Java Version

If Maven, Gradle, or another build tool still finds a different Java version, print both JAVA_HOME and the active compiler path:

printf '%s\n' "$JAVA_HOME"
readlink -f "$(command -v javac)"

For the OpenJDK 8 JDK, JAVA_HOME should normally point to /usr/lib/jvm/java-8-openjdk-amd64. Update your shell profile if it still points to another Java installation.

Remove OpenJDK 8 from Ubuntu

Remove the OpenJDK 8 packages that match the install path you used. Including the headless packages is safe when they are installed as OpenJDK 8 dependencies:

sudo apt remove openjdk-8-jdk openjdk-8-jre openjdk-8-jdk-headless openjdk-8-jre-headless

Preview autoremovable dependencies before accepting cleanup. This matters on reused systems where unrelated old packages may already be marked as autoremovable:

sudo apt autoremove --dry-run

If the preview only lists packages you are comfortable removing, run the cleanup:

sudo apt autoremove

Use package-manager state as the primary removal check:

apt-cache policy openjdk-8-jdk openjdk-8-jre
openjdk-8-jdk:
  Installed: (none)
openjdk-8-jre:
  Installed: (none)

If you also want to check the active shell command afterward, clear the shell’s command cache first. Systems with another Java version installed will switch java to that remaining version instead of returning an error:

hash -r
java -version

Conclusion

OpenJDK 8 is installed from Ubuntu’s universe packages and ready for legacy Java applications that still depend on the Java 8 runtime or compiler. If the project also needs dependency management, install Apache Maven on Ubuntu; when the legacy constraint ends, move the workload to a newer OpenJDK LTS line.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show our tutorials more often in Top Stories and mark them as preferred in AI Mode and AI Overviews when relevant.

Add LinuxCapable as a preferred source on Google
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 coffeeBuy 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
<a href="https://example.com">link</a> link
<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.

Verify before posting: