How to Install Java on Ubuntu 26.04

By 

•

Updated on

•

7 min read

Java logo and Ubuntu branding for the Ubuntu 26.04 installation guide

Many server applications, build tools, and IDEs will not start until Java is installed. Ubuntu 26.04 ships OpenJDK 25 as its default Java, and the same repositories carry older and newer OpenJDK releases for applications that need a specific version.

This guide explains how to install OpenJDK and Oracle JDK on Ubuntu 26.04, switch between installed versions, and set the JAVA_HOME environment variable.

Quick Reference

TaskCommand
Install default JDKsudo apt install default-jdk
Install OpenJDK 21sudo apt install openjdk-21-jdk
Install OpenJDK 25sudo apt install openjdk-25-jdk
Check Java versionjava -version
Change default Javasudo update-alternatives --config java
Set JAVA_HOMEAdd to /etc/environment
Uninstall OpenJDK 25sudo apt remove openjdk-25-jdk-headless openjdk-25-jre-headless
Uninstall Oracle JDK 25sudo apt remove jdk-25

Before You Begin

There are several Java implementations available. OpenJDK and Oracle JDK are the two most common choices. OpenJDK is the default option in Ubuntu and the best fit for most systems.

Ubuntu 26.04 includes OpenJDK packages for both the Java Runtime Environment (JRE) and the Java Development Kit (JDK). The JRE includes the Java virtual machine (JVM) and the libraries needed to run Java programs. The JDK includes the JRE plus the tools needed to build Java applications.

The Ubuntu 26.04 repositories provide OpenJDK 8, 11, 17, 21, 25, and 26. Java 25 is the default version and comes from the Main repository. The other versions are in the Universe repository.

If you are not sure which package to install, start with the default OpenJDK version. Some applications require a specific Java release, so check the application documentation before you install it.

Installing OpenJDK in Ubuntu

Check if Java is already installed:

Terminal
java -version

If Java is not installed, the output will tell you the command is not found. Otherwise, it shows the installed version.

Update the package index:

Terminal
sudo apt update

Java 25 is the latest long-term support (LTS) release and the default Java in Ubuntu 26.04. The default-jdk package installs the same version.

To install OpenJDK 25, run:

Terminal
sudo apt install openjdk-25-jdk
Info
If you want to install another version, replace the version number. For example, if your application requires Java 21, install the openjdk-21-jdk package. Java 26 is listed as openjdk-26-jdk, but it reached end of support in September 2026. Canonical plans to remove it from the repositories . Use a supported release for new installations.

Verify the installation:

Terminal
java -version
output
openjdk version "25.0.4.1" 2026-08-18
OpenJDK Runtime Environment (build 25.0.4.1+1-1-26.04.4-Ubuntu)
OpenJDK 64-Bit Server VM (build 25.0.4.1+1-1-26.04.4-Ubuntu, mixed mode, sharing)

The first line shows the Java version and its release date. The Ubuntu suffix in the build string tells you the JDK came from the Ubuntu repositories.

JRE is included in the JDK package. If you need only JRE, install the openjdk-25-jre package. For a minimal Java runtime without graphical dependencies, install the openjdk-25-jre-headless package.

Installing Oracle Java in Ubuntu

Oracle JDK is not available in the default Ubuntu repositories. You can install it by downloading the .deb package from Oracle.

At the time of writing, Oracle’s downloads page offers JDK 27, the latest feature release, and JDK 25, the latest LTS release. Both are available under the Oracle No-Fee Terms and Conditions (NFTC), which allows free production use and redistribution. JDK 25 receives NFTC updates until September 2028. JDK 27 receives them only until March 2027, when JDK 28 replaces it. If you plan to standardize on Oracle JDK, review Oracle’s current licensing terms before deployment.

Visit the Oracle Java Downloads page and select the version you need.

In this example, we will download and install Java 25 because it is the current LTS release. Choose the Linux x64 Debian Package for the version you want and download the .deb file.

These Oracle package instructions require an amd64 (x86-64) system. Oracle does not provide an ARM64 .deb package. On ARM64 systems, use OpenJDK from the Ubuntu repositories or follow Oracle’s archive installation instructions for its Linux ARM64 .tar.gz download.

Oracle JDK 25 downloads page with the Linux x64 Debian Package link highlighted

If you are installing on a server, use wget to download the file:

Terminal
wget https://download.oracle.com/java/25/latest/jdk-25_linux-x64_bin.deb

For JDK 27, replace 25 with 27 in both the URL and the filename.

Install the package:

Terminal
sudo apt install ./jdk-25_linux-x64_bin.deb

Replace the filename if you downloaded a different version.

The package installs the JDK under /usr/lib/jvm/, in a directory named after the full release number, such as jdk-25.0.5.0.3-oracle-x64.

Setting the Default Java Version

If you have multiple Java versions installed, check the current default:

Terminal
java -version

In automatic mode, the installed version with the highest priority becomes the default. Oracle JDK registers a much higher priority than OpenJDK, so installing it switches the default to Oracle JDK. If you selected a version manually, your choice is kept.

Change the default version with update-alternatives:

Terminal
sudo update-alternatives --config java

You will see a list of installed Java versions:

output
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                             Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/jdk-25.0.5.0.3-oracle-x64/bin/java   419471408 auto mode
  1            /usr/lib/jvm/java-25-openjdk-amd64/bin/java       2511      manual mode
  2            /usr/lib/jvm/jdk-25.0.5.0.3-oracle-x64/bin/java   419471408 manual mode

Press <enter> to keep the current choice[*], or type selection number:

The * marks the current default. Selection 0 follows the highest priority automatically, and selections 1 and 2 pin a specific JDK in manual mode.

Enter the number of the version you want as default and press Enter.

The Java compiler has its own alternative. To switch javac to the same JDK, run:

Terminal
sudo update-alternatives --config javac

Verify that the runtime and the compiler use the version you selected:

Terminal
java -version
javac -version

Setting the JAVA_HOME Environment Variable

Some Java applications use the JAVA_HOME environment variable to determine the JDK location.

First, find the Java installation path:

Terminal
sudo update-alternatives --config java

The paths are:

  • Oracle JDK 25 is located at /usr/lib/jvm/jdk-25.0.5.0.3-oracle-x64/bin/java
  • OpenJDK 25 is located at /usr/lib/jvm/java-25-openjdk-amd64/bin/java
Info
The java binary is located at JAVA_HOME/bin/java. Set JAVA_HOME to the path above, excluding the bin/java part. The Oracle directory name changes with every Oracle JDK update, so check it before you copy the path.

Open the /etc/environment file:

Terminal
sudo nano /etc/environment

Add the following line (adjust the path for your preferred version):

/etc/environmenttxt
JAVA_HOME="/usr/lib/jvm/java-25-openjdk-amd64"

Sourcing the file sets the variable in your current shell, but it does not export it. Programs started from the shell, such as Maven or Gradle, will not see it until you export it:

Terminal
source /etc/environment
export JAVA_HOME

Verify the variable is exported:

Terminal
printenv JAVA_HOME
output
/usr/lib/jvm/java-25-openjdk-amd64

Other login sessions pick up the new setting after you sign out and sign back in.

Info
/etc/environment is system-wide. To set JAVA_HOME per user, add export JAVA_HOME="/usr/lib/jvm/java-25-openjdk-amd64" to ~/.bashrc or another shell configuration file.

Uninstalling Java

OpenJDK is split across several packages. Removing only openjdk-25-jdk leaves the runtime and headless development tools installed. To remove OpenJDK 25, remove both headless packages; apt also removes the JDK and JRE packages that depend on them.

Check the proposed removals first, especially if other applications depend on Java:

Terminal
apt --simulate remove openjdk-25-jdk-headless openjdk-25-jre-headless

If the removal list is correct, run:

Terminal
sudo apt remove openjdk-25-jdk-headless openjdk-25-jre-headless

Replace 25 in both package names with the version you want to remove.

Oracle JDK is installed as the jdk-25 package. To remove it, run:

Terminal
sudo apt remove jdk-25

For Oracle JDK 27, the package name is jdk-27.

Conclusion

OpenJDK 25 from the Ubuntu repositories works for most applications on Ubuntu 26.04 and receives updates through apt. Install Oracle JDK when a vendor requires it, and set JAVA_HOME explicitly when a project pins a specific Java version.

To check which Java version a system is running, see our guide on how to check the Java version .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page