How to Install Java 25 on Ubuntu
Install Java 25 LTS on Ubuntu from Ubuntu's repositories, Eclipse Temurin or the official archive, then set JAVA_HOME and run your app as a service.

Java 25 is a long-term support (LTS) release, which makes it the version to standardise on for new projects and servers. This guide shows three ways to install it on Ubuntu, how to switch between Java versions, how to set JAVA_HOME, and how to run a Java application as a service on a server.
Before You Start
- An Ubuntu system such as Ubuntu 24.04 LTS, on your computer or on an Ubuntu VPS.
- A user with
sudorights. New to the server? Follow our Ubuntu VPS setup guide first. - At least 1 GB of free RAM for small programs; real applications usually need 2 GB or more.
Check whether Java is already installed and which version it is:
java -version
If the command is not found, no Java is installed yet. If an older version shows up, you can install Java 25 next to it and choose which one to use later.
JDK or JRE: Which One Do You Need?
The JDK (Java Development Kit) contains the compiler and developer tools as well as the runtime. Install it if you build Java code or are not sure. On a server that only runs finished applications, the headless JDK package leaves out the graphical libraries and saves disk space.
Method 1: Install Java 25 from Ubuntu's Repositories
The simplest option, when your Ubuntu release offers Java 25. First see whether the package is available:
sudo apt update
apt-cache search openjdk-25
If openjdk-25-jdk appears in the list, install it:
sudo apt install -y openjdk-25-jdk
# or, on a server without a desktop:
sudo apt install -y openjdk-25-jdk-headless
If the search returns nothing, your release does not package Java 25 yet. Use Method 2.
Method 2: Install Eclipse Temurin 25 (Recommended for Servers)
Eclipse Temurin is a free, widely used OpenJDK build with its own Ubuntu repository. It works on all current Ubuntu releases and receives updates through apt like any other package.
Add the repository's signing key and the repository itself:
sudo apt install -y wget gpg
wget -qO- https://packages.adoptium.net/artifactory/api/gpg/key/public \
| sudo gpg --dearmor -o /usr/share/keyrings/adoptium.gpg
echo "deb [signed-by=/usr/share/keyrings/adoptium.gpg] https://packages.adoptium.net/artifactory/deb $(. /etc/os-release && echo $VERSION_CODENAME) main" \
| sudo tee /etc/apt/sources.list.d/adoptium.list
Then install the JDK:
sudo apt update
sudo apt install -y temurin-25-jdk
Method 3: Install from the Official Archive
If you want a JDK that apt does not manage, for example to keep several builds side by side in one folder, download the archive from the OpenJDK site (jdk.java.net/25). First check your processor architecture:
uname -m
x86_64 needs the x64 archive; aarch64 (for example an ARM64 server) needs the AArch64 one. Copy the download link for your architecture from the site, then:
cd /tmp
wget -O jdk25.tar.gz "PASTE-THE-DOWNLOAD-LINK-HERE"
sudo mkdir -p /opt/java
sudo tar -xzf jdk25.tar.gz -C /opt/java
ls /opt/java
Register it so the java command finds it (adjust the folder name to what ls showed):
sudo update-alternatives --install /usr/bin/java java /opt/java/jdk-25/bin/java 2500
sudo update-alternatives --install /usr/bin/javac javac /opt/java/jdk-25/bin/javac 2500
Archives are not updated automatically: repeat these steps when a security update comes out.
Check the Installation
java -version
javac -version
Both commands should report version 25.
Switch Between Java Versions
With more than one JDK installed, choose the default for the whole system:
sudo update-alternatives --config java
sudo update-alternatives --config javac
Type the number next to Java 25 and press Enter. Projects that need an older version can still call it by its full path.
Set JAVA_HOME
Build tools such as Maven and Gradle, and many applications, look for the JAVA_HOME variable. Find the folder of the active JDK:
dirname $(dirname $(readlink -f $(which java)))
It prints a path such as /usr/lib/jvm/java-25-openjdk-amd64 or /usr/lib/jvm/temurin-25-jdk-amd64. Set it for every user:
echo 'export JAVA_HOME=/usr/lib/jvm/temurin-25-jdk-amd64' | sudo tee /etc/profile.d/java.sh
source /etc/profile.d/java.sh
echo $JAVA_HOME
Replace the path with the one the first command printed.
Run Your First Program
Since Java 11 you can run a single source file without compiling it first. Create Hello.java:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello from Java " + Runtime.version());
}
}
java Hello.java
Java 25 also lets small programs skip the class around main, which makes quick scripts and first lessons shorter.
Run a Java Application as a Service
On a server, let systemd start your application at boot and restart it if it stops. Create a dedicated user and a unit file, for example /etc/systemd/system/myapp.service:
[Unit]
Description=My Java application
After=network.target
[Service]
User=myapp
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/java -Xms256m -Xmx1g -jar /opt/myapp/app.jar
Restart=on-failure
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
sudo useradd --system --home /opt/myapp myapp
sudo systemctl daemon-reload
sudo systemctl enable --now myapp
sudo systemctl status myapp
Set -Xmx well below the server's total RAM: the JVM needs memory outside the heap, and the operating system needs some too. As a rule of thumb, give the heap no more than half to two-thirds of the RAM on a server that runs only this application. When the application outgrows the server, you can move to a bigger cloud VPS without reinstalling.
Remove Java
sudo apt remove openjdk-25-jdk # Method 1
sudo apt remove temurin-25-jdk # Method 2
For an archive install, delete the folder in /opt/java and remove its alternatives with sudo update-alternatives --remove java /opt/java/jdk-25/bin/java.
Troubleshooting
- "Unable to locate package openjdk-25-jdk": your Ubuntu release does not include Java 25. Use Method 2.
java -versionstill shows an old version: runsudo update-alternatives --config javaand pick Java 25, then open a new terminal.- "cannot execute binary file": the archive does not match your processor. Check
uname -mand download the right one. - The application is killed under load: the server is running out of memory. Lower
-Xmxor add RAM.