How to Install Java 25 on Ubuntu 26.04

How to Install Java 25 on Ubuntu 26.04

Java remains one of the most powerful, versatile, and relevant programming languages in the world. Java 25 brings exciting new features like primitive pattern matching, compact object headers, and improved performance for virtual threads. If you overlook these improvements, your applications may run more slowly, and you will be stuck with outdated coding practices that can leave you behind. In this article, we will show you how to install Java 25 on Ubuntu 26.04

Prerequisites

Conventions

# – given commands should be executed with root privileges either directly as a root user or by use of sudo command
$ – given commands should be executed as a regular user

Step 1. Update the System

First of all, we need to log in to our Ubuntu 26.04 VPS through SSH:

ssh root@IP_Address -p Port_number

Replace “root” with a user that has sudo privileges. Additionally, replace “IP_Address” and “Port_Number” with your server’s respective IP address and SSH port number. Next, let’s make sure that we’re on Ubuntu 26.04. You can verify it with this command:

# lsb_release -a

You should get this as the output:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu Resolute Raccoon 
Release:        26.04
Codename:       resolute

Then, run the following command to make sure that all installed packages on the server are updated to their latest available versions:

# apt update 

That’s it, the system package information should be updated now.

Step 2. Install from APT

This is the most preferred way to install Java. Installing Java from the APT repository will provide automatic updates through the package manager. At the moment, the Java JRE and JDK are not available in the Ubuntu APT repository. But when they are available, you can simply run this command to install JRE.

# apt install openjdk-25-jdk

The command above will install the Java Development Kit. The JDK includes the compiler, debugger, and all development tools.

If you do not have a plan to develop a Java application on your server and only want to run a Java application, you can install the Java Runtime Environment.

# apt install openjdk-25-jre

The JRE package is smaller and excludes development tools, making it suitable for a production server.

Step 3. Manual Install

This installation method will give you access to the latest features but requires manual update management. Let’s download the package.

# cd /tmp
# wget https://download.oracle.com/java/25/latest/jdk-25_linux-x64_bin.tar.gz
# mkdir /opt/java-jdk

Then, extract the downloaded file.

# tar -xzf jdk-25_linux-x64_bin.tar.gz -C /opt/java-jdk

Now, check the exact directory name:

# ls -lh /opt/java-jdk/

You will see a directory named jdk-25, jdk-25.0.2, or something similar. Note this exact name.

Configure update-alternatives. Replace jdk-25.0.2 with your actual directory name:

# update-alternatives --install /usr/bin/java java /opt/java-jdk/jdk-25.0.2/bin/java 1
# update-alternatives --install /usr/bin/javac javac /opt/java-jdk/jdk-25.0.2/bin/javac 1

Set both java and javac to the same version. Mismatched versions cause compilation issues:

# update-alternatives --config java
# update-alternatives --config javac

Select the Java 25 option for both commands. Verify installation:

# java -version
# javac -version

Both should display matching Java 25 version information, because, as said earlier, mismatched versions cause compilation issues.

java 25.0.2 2026-01-20 LTS
Java(TM) SE Runtime Environment (build 25.0.2+10-LTS-69)
Java HotSpot(TM) 64-Bit Server VM (build 25.0.2+10-LTS-69, mixed mode, sharing)
javac 25.0.2

Step 4. Set JAVA_HOME Environment Variable

Many Java applications require the JAVA_HOME environment variable. Maven, Gradle, Tomcat, and other tools check this variable to locate Java. Find your installation path. For apt-installed Java:

# update-alternatives --display java

Look for the line showing where the link points. JAVA_HOME should be the directory path excluding /bin/java.

For manual installations:

# ls -lh /opt/java-jdk/

For system-wide configuration, we can edit the system environment file:

# nano /etc/environment

Add this line (make sure to use your Java path):

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

For manual installations:

JAVA_HOME="/opt/java-jdk/jdk-25.0.2"

Use the exact directory name from your installation. Save the file, then exit from the editor. To apply the changes, we need to execute this command:

# source /etc/environment
# echo $JAVA_HOME

The echo command confirms proper configuration.

Now, if you want to set JAVA_HOME only for your user account, run this command from your own system account.

$ nano ~/.bashrc

Add these lines to the file:

$ export JAVA_HOME="/usr/lib/jvm/java-25-openjdk-amd64"
$ export PATH=$PATH:$JAVA_HOME/bin

To apply the changes, invoke the command below.

$ source ~/.bashrc
$ echo $JAVA_HOME

This user-specific configuration method isolates it to your account without affecting other users.

In Conclusion

That’s it all! You have learned how to install Java 25 on Ubuntu 26.04

Of course, you don’t have to install Java 25 on Ubuntu 26.04 if you use one of our managed Java hosting services, in which case you can simply ask our expert Linux admins to install Java 25 on Ubuntu 26.04 for you. They are available 24×7 and will take care of your request immediately. Managing a website is not just about installation; we can help you optimize it if you have an active service with us.

If you liked this post on how to install Java 25 on Ubuntu 26.04, please share it with your friends or simply leave a comment below.

Leave a Comment