How To

Install Java 8 (OpenJDK 8) on Ubuntu 24.04 / 22.04

Java 8 remains the runtime for a surprising number of production applications, build tools, and enterprise systems that haven’t migrated to newer LTS versions. If you’re running legacy Java apps on Ubuntu, OpenJDK 8 is available directly from Ubuntu’s repositories on both 24.04 and 22.04.

Original content from computingforgeeks.com - post 8014

This guide covers installing OpenJDK 8 (JDK and JRE), setting JAVA_HOME, and switching between multiple Java versions when you need both Java 8 and a newer JDK on the same system. For the latest LTS release, see the guide on installing Java 21 on Ubuntu.

Verified working: March 2026 on Ubuntu 24.04.4 LTS with OpenJDK 1.8.0_482

Prerequisites

  • Ubuntu 24.04 LTS or 22.04 LTS
  • sudo access
  • About 400 MB of disk space for the full JDK

Install OpenJDK 8 JDK

Update the package index and install the full JDK (includes compiler, tools, and JRE):

sudo apt update
sudo apt install -y openjdk-8-jdk

The JDK package pulls in the JRE as a dependency, so you get both. Verify the installation:

java -version

The output confirms OpenJDK 8:

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

Check the compiler version too:

javac -version

This should show javac 1.8.0_482.

Install Only the JRE

If you only need to run Java applications (no compilation), install just the JRE for a smaller footprint:

sudo apt install -y openjdk-8-jre

The JRE is about half the size of the full JDK. Use it for production servers that only run compiled Java applications.

Set JAVA_HOME

Many Java applications and build tools (Maven, Gradle, Tomcat) require the JAVA_HOME environment variable. On Ubuntu 24.04, the OpenJDK 8 path is:

/usr/lib/jvm/java-8-openjdk-amd64

Set it permanently for all users by adding it to /etc/environment:

echo 'JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"' | sudo tee -a /etc/environment

Load the change in the current session:

source /etc/environment
echo $JAVA_HOME

You should see /usr/lib/jvm/java-8-openjdk-amd64 printed. For a single user, add the export line to ~/.bashrc instead of /etc/environment.

Switch Between Java Versions

Ubuntu’s alternatives system lets you install multiple Java versions side by side and switch the system default. This is common when some applications need Java 8 while newer tools require Java 17 or 21.

List all installed Java versions:

update-alternatives --list java

With Java 8, 11, 17, and 21 all installed, the output looks like:

/usr/lib/jvm/java-11-openjdk-amd64/bin/java
/usr/lib/jvm/java-17-openjdk-amd64/bin/java
/usr/lib/jvm/java-21-openjdk-amd64/bin/java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

Switch to a specific version with:

sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

The system confirms the switch:

update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode

Don’t forget to also switch the compiler if you use javac:

sudo update-alternatives --set javac /usr/lib/jvm/java-8-openjdk-amd64/bin/javac

Remember to update JAVA_HOME accordingly when switching versions, especially for build tools like Apache Maven that depend on it.

Java Versions on Ubuntu 24.04

VersionPackageJAVA_HOME pathStatus
Java 8 (LTS)openjdk-8-jdk/usr/lib/jvm/java-8-openjdk-amd64Available, legacy support
Java 11 (LTS)openjdk-11-jdk/usr/lib/jvm/java-11-openjdk-amd64Available
Java 17 (LTS)openjdk-17-jdk/usr/lib/jvm/java-17-openjdk-amd64Available
Java 21 (LTS)openjdk-21-jdk/usr/lib/jvm/java-21-openjdk-amd64Available, recommended
Java 25openjdk-25-jdk/usr/lib/jvm/java-25-openjdk-amd64Available, non-LTS

For new projects, Java 21 is the recommended LTS. Java 8 is best reserved for applications that specifically require it, as it is approaching end of public updates from some vendors.

Test a Java Application

Quick compile-and-run test to confirm the JDK works:

cat << 'JAVA' > Hello.java
public class Hello {
    public static void main(String[] args) {
        System.out.println("Java " + System.getProperty("java.version") + " works!");
    }
}
JAVA
javac Hello.java && java Hello

The output confirms compilation and runtime both work:

Java 1.8.0_482 works!

If you need to set the default Java version more permanently, or run Java applications as systemd services, see the guide on running Java JAR files with systemd.

Related Articles

Desktop Uninstall LibreOffice on Ubuntu and Install Alternatives Ubuntu Reset FreeIPA admin Password as root user on Linux Ubuntu How To Install VirtualBox 7.0 on Ubuntu 24.04|22.04|20.04 Monitoring Install and Configure Cacti on Ubuntu 22.04|20.04|18.04

Leave a Comment

Press ESC to close