Learn how to install Java 25 on Ubuntu 26.04 LTS using the official OpenJDK package. Follow this step by step guide to install Java, configure JAVA_HOME, verify the installation, and run your first Java program.
What is Java?
Java is one of the most popular programming languages used to build web applications, desktop software, enterprise applications, and Android apps. If you are planning to develop Java applications or run Java based software, installing the Java Development Kit (JDK) is the right choice.
Ubuntu 26.04 LTS includes OpenJDK 25 as its default Java version. Since Java 25 is the latest Long Term Support (LTS) release, you can install it directly from the official Ubuntu repository without adding any third party repository.
Prerequisites
Before you begin, make sure you have:
- A dedicated server or desktop running Ubuntu 26.04 LTS
- A user account with sudo privileges
- Internet access
Let's start Learning how to install Java 25 on Ubuntu 26.04 LTS using the official OpenJDK package
Step 1: Update the Package List
It is always a good idea to refresh your package list before installing new software.
sudo apt update
Step 2: Install Java 25
Install the latest OpenJDK 25 package by running:
sudo apt install openjdk-25-jdk
Press Y when Ubuntu asks for confirmation.
The installation may take a few minutes depending on your internet connection.
Step 3: Verify the Installation
Once the installation is complete, check the installed Java version.
java -version
You should see output similar to:
openjdk version "25.0.3" 2026-04-21
OpenJDK Runtime Environment (build 25.0.3+9-2-26.04.2-Ubuntu)
OpenJDK 64-Bit Server VM (build 25.0.3+9-2-26.04.2-Ubuntu, mixed mode, sharing)
Next, verify that the Java compiler is also installed.
javac -version
Example output:
javac 25.x.x
If both commands display version 25, Java has been installed successfully.
Step 4: Check the Installed Java Location
If you would like to know where Java is installed, run:
which java
Example output:
/usr/bin/java
To see the actual installation directory, run:
readlink -f /usr/bin/java
Example output:
/usr/lib/jvm/java-25-openjdk-amd64/bin/java
Step 5: Check the JAVA_HOME Path
Many Java applications require the JAVA_HOME environment variable.
To find the Java installation directory, run:
readlink -f $(which java)
The output will look similar to:
/usr/lib/jvm/java-25-openjdk-amd64/bin/java
Your JAVA_HOME path is:
/usr/lib/jvm/java-25-openjdk-amd64
Step 6: Set the JAVA_HOME Environment Variable
Open the environment file.
sudo nano /etc/environment
Add the following line at the end of the file.
JAVA_HOME="/usr/lib/jvm/java-25-openjdk-amd64"
Save the file and exit the editor.
Reload the environment variables.
source /etc/environment
Verify that the variable is available.
echo $JAVA_HOME
Expected output:
/usr/lib/jvm/java-25-openjdk-amd64
Step 7: Create a Simple Java Program
Create a new Java file.
nano HelloWorld.java
Paste the following code.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Save the file.
Compile the program.
javac HelloWorld.java
Run the program.
java HelloWorld
Output:
Hello, World!
This confirms that both the Java compiler and runtime are working correctly.
Check the Default Java Version
If you have multiple Java versions installed, you can check which version is currently active.
java -version
You can also list the installed Java versions.
update-java-alternatives --list
If multiple versions are available, select the one you want.
sudo update-alternatives --config java
Choose the number corresponding to Java 25.
Uninstall Java 25
If you no longer need Java 25, remove it with the following command.
sudo apt remove openjdk-25-jdk
To remove packages that are no longer required, run:
sudo apt autoremove
Conclusion
You have successfully installed Java 25 on Ubuntu 26.04 LTS. The installation uses the official Ubuntu repository, making it easy to receive future security updates through the standard package manager. You also verified the installation, configured the JAVA_HOME variable, and tested Java by compiling and running your first program. Since Java 25 is the default LTS release in Ubuntu 26.04, it is a great choice for both development and production environments.

