How to Install Java on Ubuntu 26.04
Introduction
Java is a popular programming language used to run web applications, enterprise software, game servers, and development tools.
Ubuntu 26.04 provides OpenJDK packages directly from its official repositories. OpenJDK is suitable for most users, while Oracle JDK can be installed manually when required.
This guide explains how to install OpenJDK and Oracle JDK on Ubuntu 26.04.
Check Whether Java Is Installed
Run:
java -version
If Java is not installed, the system will return a command not found message.
Install OpenJDK
Update the package index:
sudo apt update
Install the default Java Development Kit:
sudo apt install default-jdk -y
On Ubuntu 26.04, the default JDK package installs OpenJDK 25. You can also install it directly with:
sudo apt install openjdk-25-jdk -y
Verify the installation:
java -version
Check the Java compiler:
javac -version
For applications requiring Java 21, install it with:
sudo apt install openjdk-21-jdk -y
For systems that only need to run Java applications without development tools, install the headless runtime:
sudo apt install openjdk-25-jre-headless -y
Install Oracle JDK
Oracle JDK is not included in the default Ubuntu repositories. Download the Debian package from Oracle:
wget https://download.oracle.com/java/25/latest/jdk-25_linux-x64_bin.deb
Install the downloaded package:
sudo apt install ./jdk-25_linux-x64_bin.deb -y
Verify the installation:
java -version
Review Oracle’s current licensing terms before using Oracle JDK in a production environment.
Change the Default Java Version
When multiple Java versions are installed, display the available versions with:
sudo update-alternatives --config java
Enter the number corresponding to the Java version you want to use.
Configure the default Java compiler separately:
sudo update-alternatives --config javac
Confirm the selected version:
java -version javac -version
Configure JAVA_HOME
Some applications require the JAVA_HOME environment variable.
Find the active Java installation path:
readlink -f "$(which java)"
For OpenJDK 25, the path is normally:
/usr/lib/jvm/jdk-25.0.3-oracle-x64/bin/java
Open the system environment file:
sudo nano /etc/environment
Add:
JAVA_HOME="/usr/lib/jvm/jdk-25.0.3-oracle-x64"
Apply the configuration:
source /etc/environment
Verify it:
echo $JAVA_HOME
Uninstall Java
Remove OpenJDK 25 with:
sudo apt remove openjdk-25-jdk -y sudo apt autoremove -y
List installed Java packages:
dpkg -l | grep -E 'openjdk|jdk'
Conclusion
Java is now installed on Ubuntu 26.04.
OpenJDK 25 is the recommended option for most systems because it is available directly from the Ubuntu repositories. You can install another Java version when required and use update-alternatives to select the default version.