How To Install Java on Ubuntu 26.04 LTS

Install Java on Ubuntu 26.04

Java still runs a huge portion of the modern software world. Enterprise backends, Android toolchains, big data platforms like Apache Kafka and Apache Spark, CI/CD pipelines, and game servers like Minecraft all depend on a working Java runtime. If you are setting up a fresh Ubuntu 26.04 LTS server or development machine, knowing how to install Java on Ubuntu 26.04 LTS correctly from the start saves you hours of debugging later.

This guide covers everything you need. You will learn the difference between the JRE and JDK, how to pick the right Java version for your workload, two proven installation methods, how to configure JAVA_HOME, how to switch between multiple Java versions, and how to fix the most common errors people run into. Every command comes with a clear explanation of what it does and why it matters, not just what to type.

Ubuntu 26.04 LTS ships with OpenJDK 25 as the default Java version in its repositories, supported through September 2033. For enterprise teams that need TCK-certified builds with faster security patch cadences, Eclipse Temurin 25 is the better choice. Both methods are covered here.

Table of Contents

Prerequisites

Before you touch a single command, make sure your environment meets these requirements:

  • Ubuntu 26.04 LTS installed, either desktop or server edition. Both work identically for this guide.
  • A user account with sudo privileges. Package installation writes to protected system directories. Running commands as a regular user without sudo will fail, and running everything as root directly is a security risk you do not need to take.
  • An active internet connection. The apt package manager fetches packages from Ubuntu’s remote repositories in real time.
  • Basic terminal familiarity. You need to know how to open a terminal, type commands, and navigate directories.
  • Know your Java version requirement ahead of time. Spring Boot 3.x requires Java 17 or higher. Elasticsearch 8.x requires Java 21. Some legacy enterprise platforms still mandate Java 11. Choosing the wrong version now costs you time later.

JRE vs JDK: Which One Do You Actually Need?

This is the question most beginner tutorials skip, and it causes a lot of confusion.

JRE (Java Runtime Environment) is the minimum software needed to run compiled Java applications. It contains the Java Virtual Machine (JVM) and the standard class libraries. Install this if you are only executing pre-built Java programs, for example running a .jar file or hosting a pre-compiled application server.

JDK (Java Development Kit) is a superset of the JRE. It includes everything the JRE has, plus the Java compiler (javac), the jar tool, jshell, and other development utilities. Install this if you are writing code, compiling source files, or using build tools like Maven or Gradle.

The practical rule: when in doubt, install the JDK. The extra disk space is negligible and it prevents the frustrating “command not found: javac” error that trips up a lot of new Linux users.

Which Java Version Should You Install on Ubuntu 26.04 LTS?

Ubuntu 26.04 LTS provides multiple Java versions in its repositories. The right choice depends entirely on your project requirements.

Java Version LTS Support Until Best Use Case
OpenJDK 8 December 2030 Legacy apps, Spring 4.x, vendor-locked platforms
OpenJDK 11 September 2027 Older enterprise systems, legacy frameworks
OpenJDK 17 September 2029 Spring Boot 3.x, Jakarta EE 10+
OpenJDK 21 September 2031 Virtual threads, high-concurrency workloads
OpenJDK 25 September 2033 New projects, latest LTS, default on Ubuntu 26.04

For any new project in 2026, start with OpenJDK 25. If your framework has not yet certified Java 25, go with Java 21, which brings virtual threads and structured concurrency from Project Loom.

Step 1: Update Your System Package Index

The first thing any experienced sysadmin does before installing new software is update the local package index. This is not just a ritual. It matters.

sudo apt update
sudo apt upgrade -y

Why apt update first: This command contacts Ubuntu’s remote repositories and downloads the current list of available packages and their versions. Without it, apt works from a potentially outdated local cache and may install an older version of OpenJDK or fail entirely with an “Unable to locate package” error.

Why apt upgrade: Upgrading existing packages before adding new ones prevents dependency conflicts. A stale library from three months ago can block a new package from installing cleanly, especially on servers that have not been updated in a while.

What to expect: apt will print a list of packages being refreshed. On a fresh Ubuntu 26.04 install this takes around one to three minutes depending on your internet connection.

Step 2: Install Java on Ubuntu 26.04 LTS (OpenJDK 25 via APT)

This is the Java on Ubuntu 26.04 LTS setup path most users should take. Ubuntu’s official repositories maintain OpenJDK 25 and push security updates through the normal apt upgrade mechanism, which means no external repositories, no GPG key management, and no additional maintenance overhead.

Install the Java Runtime Environment (JRE Only)

sudo apt install openjdk-25-jre

Why: This installs the JRE for OpenJDK 25. It gives you everything needed to run Java applications on this server. The -jre package is the smallest footprint option, ideal for production servers where you are only executing pre-built .jar files.

Install the Full Java Development Kit (JDK)

sudo apt install openjdk-25-jdk

Why: The JDK includes everything from the JRE, plus the javac compiler, jar tool, jshell REPL, and development headers. You need this if you are writing code, running Maven builds, using Gradle, or developing inside an IDE like IntelliJ IDEA.

For headless server environments like Docker containers or CI/CD build agents without a display, use the headless variants instead:

sudo apt install openjdk-25-jre-headless
# or
sudo apt install openjdk-25-jdk-headless

Why headless: These packages exclude graphical libraries (GTK, X11), which reduces the installation footprint significantly. On a build server, you do not need a GUI toolkit bundled with your Java install.

Verify the Installation

java --version
javac --version

Expected output:

openjdk 25.0.1 2025-10-21
OpenJDK Runtime Environment (build 25.0.1+8-Ubuntu-2)
OpenJDK 64-Bit Server VM (build 25.0.1+8-Ubuntu-2, mixed mode, sharing)

javac 25.0.1

Why verify: Running java --version confirms the binary is on PATH and the install completed without silent errors. If javac returns “command not found” here, you installed the JRE instead of the JDK. Run the JDK install command above and verify again.

Step 3: Install a Specific Java Version

Sometimes your project or employer mandates a specific Java version. Spring Boot 3.x requires Java 17 or higher. Elasticsearch 8.x requires Java 21. Some enterprise platforms still run only on Java 11. Here is how to install any specific version on Ubuntu 26.04 LTS.

Install OpenJDK 21

sudo apt install openjdk-21-jdk

Why Java 21: It introduces virtual threads via Project Loom, making it the recommended choice for high-concurrency server applications in 2026. Virtual threads let you run thousands of concurrent tasks without the memory overhead of traditional OS threads.

Install OpenJDK 17

sudo apt install openjdk-17-jdk

Why Java 17: Spring Boot 3.x requires Java 17 as its minimum. Jakarta EE 10+ also targets Java 17. If you are running any modern Spring-based backend, this is likely your version.

Install OpenJDK 11

sudo apt install openjdk-11-jdk

Why Java 11: Legacy enterprise applications and some vendor-certified platforms have not yet migrated past Java 11. Install this only if your application documentation explicitly requires it.

Important note: Installing a specific version does not make it the active default if another version was already installed. The update-alternatives section below covers exactly how to switch.

Step 4: Install Eclipse Temurin for Enterprise Environments

Eclipse Temurin is the enterprise-grade OpenJDK distribution from the Adoptium project. These builds are TCK-certified (Technology Compatibility Kit), meaning they pass the official Java compatibility test suite. They also pass the AQAvit verification suite, which adds additional quality and security checks.

Use Temurin when your organization requires vendor-certified builds, when you need security patches faster than Ubuntu’s release cycle provides, or when your compliance requirements mandate a specific certification standard.

Step 4a: Import the Adoptium GPG Key

curl -fsSL https://packages.adoptium.net/artifactory/api/gpg/key/public | \
  gpg --dearmor | sudo tee /usr/share/keyrings/adoptium.gpg > /dev/null

Why: This downloads and installs Adoptium’s cryptographic signing key. Every package from Adoptium’s repository is signed with this key. APT uses it to verify that packages have not been tampered with between Adoptium’s servers and your machine. Without this step, adding the repository would fail or leave you vulnerable to a package swap attack.

Step 4b: Add the Adoptium APT Repository

cat <<EOF | sudo tee /etc/apt/sources.list.d/adoptium.sources
Types: deb
URIs: https://packages.adoptium.net/artifactory/deb
Suites: $(. /etc/os-release && echo $VERSION_CODENAME)
Components: main
Architectures: $(dpkg --print-architecture)
Signed-By: /usr/share/keyrings/adoptium.gpg
EOF

Why $VERSION_CODENAME: This shell substitution automatically detects your Ubuntu release codename and inserts the correct value. It prevents the common mistake of hardcoding “noble” or “jammy” and accidentally pointing to the wrong repository for your OS version.

Why $(dpkg --print-architecture): Automatically detects whether you are running on amd64, arm64, or another architecture. This is critical on ARM-based servers like AWS Graviton or Raspberry Pi, where the wrong architecture string causes package resolution failures.

Step 4c: Refresh the Package Index and Install

sudo apt update
sudo apt install temurin-25-jdk

Step 4d: Verify Temurin Installation

java --version

Expected output:

openjdk 25.0.1 2025-10-21 LTS
OpenJDK Runtime Environment Temurin-25.0.1+8 (build 25.0.1+8-LTS)
OpenJDK 64-Bit Server VM Temurin-25.0.1+8 (build 25.0.1+8-LTS, mixed mode, sharing)

The LTS tag in the output confirms you are running a Temurin build, not a standard Ubuntu OpenJDK package.

Step 5: Configure Java on Ubuntu 26.04 LTS with JAVA_HOME

Setting JAVA_HOME is one of the most important post-install steps that tutorials often gloss over. Build tools like Maven and Gradle, application servers like Apache Tomcat and WildFly, and IDEs like IntelliJ IDEA all look for the JAVA_HOME environment variable to locate your JDK. If it is not set, or if it points to the wrong location, you get “JAVA_HOME is not defined” errors in your builds and server startup scripts.

Find the Correct Java Installation Path

dirname $(dirname $(readlink -f $(which java)))

Why this command: It traces the symlink chain from /usr/bin/java back through Ubuntu’s alternatives system to the actual JDK directory on disk. Never hardcode a path without checking this first. The actual path varies between amd64 and arm64 architectures.

Expected output on 64-bit (amd64):

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

Expected output on ARM64:

/usr/lib/jvm/java-25-openjdk-arm64

Set JAVA_HOME for the Current User

echo 'export JAVA_HOME=/usr/lib/jvm/java-25-openjdk-amd64' >> ~/.bashrc
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

Why source ~/.bashrc: Changes written to .bashrc only take effect in new shell sessions. Running source reloads the file in your current terminal session immediately, so you do not have to log out and back in.

Set JAVA_HOME System-Wide (Recommended for Servers)

For servers running multiple users or services managed by systemd, set JAVA_HOME at the system level:

sudo nano /etc/environment

Add this line to the file:

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

Save with Ctrl+O, exit with Ctrl+X, then reload:

source /etc/environment

Why /etc/environment: Unlike .bashrc, this file applies to all users and all login sessions, including non-interactive shells used by cron jobs and systemd service units. Build pipelines and application servers that run as dedicated service users need this.

Verify JAVA_HOME

echo $JAVA_HOME

Expected output:

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

Step 6: Manage Multiple Java Versions with update-alternatives

Real-world servers and development machines often need more than one Java version installed simultaneously. A legacy application may require Java 11 while a new microservice needs Java 25. Ubuntu manages this cleanly through update-alternatives, which controls symlinks in /usr/bin/ without you touching PATH variables manually.

List All Installed Java Versions

sudo update-alternatives --list java

Why: This shows the exact filesystem path of every installed JVM before you attempt any switch.

Switch the Default Java Runtime Interactively

sudo update-alternatives --config java

Why interactive mode: This command presents a numbered menu of all detected Java versions along with their priority values. You type a number to select, then press Enter. No path memorization needed.

Sample output:

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

  Selection    Path                                         Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-25-openjdk-amd64/bin/java   2511      auto mode
  1            /usr/lib/jvm/java-21-openjdk-amd64/bin/java   2111      manual mode
  2            /usr/lib/jvm/java-25-openjdk-amd64/bin/java   2511      manual mode

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

Switch the Java Compiler to Match

sudo update-alternatives --config javac

Why you must do both: Compiling code with OpenJDK 25 while running it on OpenJDK 11 triggers “unsupported major.minor version” errors at runtime. The class file version produced by the compiler must be compatible with the JVM version executing it. Always switch both java and javac to the same version.

Confirm the Active Version

java --version && javac --version

Both outputs should show the same Java version number. If they differ, repeat the update-alternatives --config steps for whichever one is mismatched.

Step 7: Test That Your Java Installation Works

java --version proves the binary is reachable. It does not prove the full toolchain works. A quick compile-and-run test catches broken installations before you spend an afternoon debugging a Maven build or a Tomcat startup failure.

Create a Test File

nano Hello.java

Add the following code:

void main() {
    System.out.println("Java works on Ubuntu 26.04 LTS!");
    System.out.println("Version: " + System.getProperty("java.version"));
}

Save with Ctrl+O, exit with Ctrl+X.

Compile and Run

javac Hello.java
java Hello

Expected output:

Java works on Ubuntu 26.04 LTS!
Version: 25.0.1

Why this specific test: This uses Java 25’s finalized compact source file syntax, which removes the mandatory class wrapper for simple programs. If OpenJDK 25 is genuinely active, it compiles cleanly. If an older version is masquerading as 25, javac will throw a syntax error. This gives you real confirmation beyond just a version number.

Troubleshooting Common Java Installation Problems on Ubuntu 26.04 LTS

“Unable to locate package openjdk-XX-jdk”

Why it happens: On minimal Ubuntu installs, the universe repository may be disabled. Some OpenJDK versions live in universe, not main.

Fix:

sudo add-apt-repository universe
sudo apt update
sudo apt install openjdk-25-jdk

Why the fix works: Ubuntu splits its repositories into components. The main component contains officially supported packages. universe contains community-maintained packages, including some OpenJDK versions. Enabling it makes them available to apt.

“java: command not found” After Installation

Why it happens: The install completed but Java’s binary directory is not on PATH, or the installation itself failed silently.

Fix:

which java
ls /usr/lib/jvm/

If which java returns nothing but the JVM directory exists, add it to PATH manually in ~/.bashrc. If the JVM directory is empty, re-run the install command and watch for error output.

Wrong Java Version Active After Installing a New One

Why it happens: update-alternatives assigns a priority to each Java version at install time. A previously installed version with a higher priority stays as the default.

Fix:

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

Select the correct version number from the menu for both commands, then run java --version to confirm.

“JAVA_HOME is not defined” in Maven, Gradle, or Tomcat

Why it happens: You set JAVA_HOME in ~/.bashrc, but your build tool or service runs in a non-interactive shell that does not source .bashrc.

Fix:

sudo nano /etc/environment
# Add: JAVA_HOME="/usr/lib/jvm/java-25-openjdk-amd64"
source /etc/environment

This makes JAVA_HOME available to all users and all shell types, including systemd service units.

“Unsupported major.minor version” at Runtime

Why it happens: Your code was compiled against a newer Java version than the JRE executing it. For example, compiling with Java 25 and running on Java 11 produces this error because the class file format changed.

Fix: Align your compiler and runtime using update-alternatives for both java and javac. Verify with java --version && javac --version. Both must show the same version.

How to Uninstall Java from Ubuntu 26.04 LTS

Removing unused JDKs reduces your server’s attack surface, frees disk space, and prevents accidental version confusion on shared machines.

Remove OpenJDK Installed via APT

sudo apt remove openjdk-25-jdk openjdk-25-jre
sudo apt autoremove

Why autoremove: The JDK installation pulls in dozens of dependency packages. Without autoremove, those orphaned libraries stay on disk indefinitely. The autoremove command identifies and removes them safely.

Remove Eclipse Temurin

sudo apt remove temurin-25-jdk
sudo apt autoremove

To also remove the Adoptium repository and signing key:

sudo rm /etc/apt/sources.list.d/adoptium.sources
sudo rm /usr/share/keyrings/adoptium.gpg
sudo apt update

Clean Up JAVA_HOME After Uninstalling

If you configured JAVA_HOME in ~/.bashrc or /etc/environment, remove or update that line after uninstalling. A JAVA_HOME pointing to a deleted directory causes Maven, Gradle, and Tomcat to fail with confusing errors on next startup.

nano ~/.bashrc
# Remove or update the export JAVA_HOME line
source ~/.bashrc

Congratulations! You have successfully installed Java. Thanks for using this tutorial for installing the Java programming language on the Ubuntu 26.04 LTS (Resolute Raccoon) system. For additional help or useful information, we recommend you check the Java website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!
r00t is a Linux Systems Administrator and open-source advocate with over ten years of hands-on experience in server infrastructure, system hardening, and performance tuning. Having worked across distributions such as Debian, Arch, RHEL, and Ubuntu, he brings real-world depth to every article published on this blog. r00t writes to bridge the gap between complex sysadmin concepts and practical, everyday application — whether you are configuring your first server or optimizing a production environment. Based in New York, US, he is a firm believer that knowledge, like open-source software, is best when shared freely.

Related Posts