Ubuntu 24.04 users can install Java 25 directly from the official Ubuntu repositories. The package-manager method is easier to update and audit than an unofficial installation script, and it provides both the Java runtime and the javac compiler needed for development.
This guide shows how to install Java 25 on Ubuntu 24.04 with OpenJDK, verify the installation, configure JAVA_HOME, manage multiple Java versions, and compile a working program. The commands apply to Ubuntu 24.04 LTS systems with the Noble Updates repository enabled.
Table of Contents
- What You Will Install
- Prerequisites
- Install Java 25 on Ubuntu 24.04
- Verify Java and javac
- Configure JAVA_HOME
- Manage Multiple Java Versions
- Compile and Run a Java Program
- Choose JDK, JRE, or Headless Packages
- Troubleshoot Common Errors
- Production and Security Best Practices
- Frequently Asked Questions
What You Will Install
OpenJDK is the open-source implementation of the Java Platform, Standard Edition. JDK 25 reached general availability on September 16, 2025, and is designated as a long-term-support release by most vendors. Ubuntu provides it through the openjdk-25-jdk package in Noble Updates.
The full JDK includes the Java Virtual Machine, standard libraries, the java launcher, the javac compiler, and development utilities. It is the right choice when you need to build applications. A runtime-only package is smaller, but it cannot compile source code.
Ubuntu packages receive fixes through the distribution update mechanism. The exact patch version will change over time, so the expected result in this tutorial is Java 25 rather than one hard-coded patch number.
Prerequisites
- An Ubuntu 24.04 LTS workstation, virtual machine, cloud instance, or server.
- A 64-bit architecture supported by the Ubuntu package.
- A user account with
sudoprivileges. - Internet access to the configured Ubuntu repositories.
- A terminal session. SSH is sufficient for a remote server.
Confirm the operating system and architecture before changing packages:
cat /etc/os-release
dpkg --print-architecture
The release output should identify Ubuntu 24.04 and the Noble codename. If the server runs another Ubuntu release, use the package available for that release instead of mixing repositories.
How to Install Java 25 on Ubuntu 24.04
The shortest reliable procedure is to refresh the package index, confirm that APT can see the package, and install it. Checking package policy first prevents confusion when a repository is disabled.
Step 1: Refresh the APT package index
sudo apt update
This command downloads current package metadata. It does not upgrade installed software. Review any repository errors before continuing; an incomplete package index can make an available package appear to be missing.
Step 2: Confirm that OpenJDK 25 is available
apt-cache policy openjdk-25-jdk
A valid result shows a candidate version from an Ubuntu Noble repository. If Candidate: (none) appears, follow the repository checks in the troubleshooting section rather than downloading an arbitrary binary.
Step 3: Install the Java 25 JDK
sudo apt install -y openjdk-25-jdk
APT resolves the runtime, compiler, standard libraries, and supporting packages. The -y option accepts the installation prompt. Remove it if you want to inspect and approve the package list interactively.
On systems without another Java installation, Ubuntu normally registers Java 25 as the default through the alternatives system. Systems with several JDKs may retain the existing default; the selection steps later in this guide handle that case.
Verify the Java 25 Installation
Check the runtime and compiler separately:
java --version
javac --version
The first line of each result should report version 25. The runtime output also identifies the OpenJDK build and virtual machine. The compiler output is shorter and normally begins with javac 25.
Next, locate the commands selected by your shell:
command -v java
command -v javac
readlink -f "$(command -v java)"
Ubuntu generally exposes /usr/bin/java as a symbolic link managed by update-alternatives. The final command resolves that link to the active JDK directory. This is more dependable than guessing an architecture-specific path.
Configure JAVA_HOME on Ubuntu 24.04
JAVA_HOME points build tools, application servers, and deployment scripts to a JDK installation. The java command can work without it when Java is already on PATH, but Maven, Gradle, Tomcat, and custom scripts may require the variable.
Step 1: Derive the active JDK directory
dirname "$(dirname "$(readlink -f "$(command -v java)")")"
A common result on an amd64 machine is /usr/lib/jvm/java-25-openjdk-amd64. ARM64 and other architectures use a different suffix, so copy the value reported by your own server.
Step 2: Create a system-wide profile file
sudo nano /etc/profile.d/java.sh
Add the following lines, replacing the example path if the previous command returned a different directory:
export JAVA_HOME=/usr/lib/jvm/java-25-openjdk-amd64
export PATH="$JAVA_HOME/bin:$PATH"
Save the file, make its permissions explicit, and load it into the current shell:
sudo chmod 644 /etc/profile.d/java.sh
source /etc/profile.d/java.sh
printf '%sn' "$JAVA_HOME"
"$JAVA_HOME/bin/java" --version
Files in /etc/profile.d are loaded for login shells. A running service does not automatically reread them. For a systemd service, define JAVA_HOME in its unit or an EnvironmentFile, then reload systemd and restart that specific service.
Manage Multiple Java Versions
Java 17, 21, and 25 can coexist on one Ubuntu host. Ubuntu’s alternatives system determines which executable runs when you enter java or javac.
List registered runtime choices:
update-alternatives --list java
update-alternatives --list javac
Select the default runtime and compiler:
sudo update-alternatives --config java
sudo update-alternatives --config javac
Enter the number associated with the Java 25 path. Select matching major versions for both commands; otherwise, code may be compiled by one JDK and executed by another. Clear the shell’s command cache and verify the result:
hash -r
java --version
javac --version
If you changed the active JDK, update JAVA_HOME as well. update-alternatives does not rewrite variables in your profile or service configuration.
Compile and Run a Java 25 Program
A version command confirms that binaries exist; compiling a program verifies the complete development workflow. Create a separate test directory:
mkdir -p ~/java-25-demo
cd ~/java-25-demo
nano HelloJava.java
Paste this complete source file:
public class HelloJava {
public static void main(String[] args) {
System.out.println("Java " + Runtime.version());
}
}
Compile and run it:
javac HelloJava.java
java HelloJava
javac creates HelloJava.class. The second command loads that class and prints the active runtime version. The output begins with Java 25, followed by the installed feature, interim, update, and patch components.
Java also supports source-file mode for a simple single-file program:
java HelloJava.java
Source-file mode compiles in memory and runs the program without leaving a class file for that invocation. Use a normal build system such as Maven or Gradle for multi-file production projects, dependency management, testing, and repeatable artifacts.
Choose JDK, JRE, or Headless Packages
Install only what the host needs:
| Package | Best use | Includes compiler |
|---|---|---|
openjdk-25-jdk |
Developer workstation or software build host | Yes |
openjdk-25-jdk-headless |
CI runner or server that builds Java without desktop libraries | Yes |
openjdk-25-jre-headless |
Server that only runs an existing Java application | No |
For a headless development server, install:
sudo apt install -y openjdk-25-jdk-headless
For a runtime-only server, use:
sudo apt install -y openjdk-25-jre-headless
Do not choose a runtime-only image for Maven or Gradle build jobs because those jobs need javac and other JDK tools.
Troubleshoot Common Java 25 Installation Errors
E: Unable to locate package openjdk-25-jdk
First confirm Ubuntu 24.04, then refresh the index and inspect the repository configuration:
grep -R "^Components:" /etc/apt/sources.list.d/ubuntu.sources
sudo apt update
apt-cache policy openjdk-25-jdk
The package is published in Ubuntu’s universe component. If that component is disabled, enable it with the supported Ubuntu helper:
sudo apt install -y software-properties-common
sudo add-apt-repository universe
sudo apt update
Also ensure the Noble Updates pocket is enabled. Do not add repositories for a different Ubuntu release, because mixing releases can break dependency resolution and future upgrades.
java –version still reports an older release
Your shell may be finding another executable or the alternatives selection may still point to an older JDK:
type -a java
update-alternatives --list java
sudo update-alternatives --config java
hash -r
java --version
SDK managers, manually unpacked JDKs, and custom PATH entries can take precedence over /usr/bin/java. Inspect shell profile files if type -a java shows an unexpected path first.
javac: command not found
This usually means that only a JRE was installed. Install the full JDK or headless JDK:
sudo apt install -y openjdk-25-jdk
javac --version
JAVA_HOME is not set or points to the wrong directory
Derive the path from the active executable instead of copying it from another server:
readlink -f "$(command -v java)"
dirname "$(dirname "$(readlink -f "$(command -v java)")")"
Update the profile or service environment, start a new login shell, and print the variable. Remember that sudo, cron, containers, and systemd services may use environments different from your interactive shell.
UnsupportedClassVersionError
This error means the runtime is older than the Java version used to compile the class. Confirm the Java used by the application process, not only the one in your terminal. Either run the application with Java 25 or compile for an older supported target, for example:
javac --release 21 HelloJava.java
The --release option limits language and API usage to the selected Java SE release. Test the resulting artifact on the real target runtime.
Production and Security Best Practices
- Use trusted packages. Prefer Ubuntu packages or vendor distributions with documented provenance. Avoid unknown PPAs and unaudited shell installers.
- Patch routinely. Run
sudo apt update, review available upgrades, test Java updates in staging, and deploy them through your normal change process. - Use a dedicated service account. A Java application rarely needs root privileges. Restrict file, network, database, and secret access to what the service requires.
- Choose the headless runtime for deployment. It reduces unnecessary desktop dependencies when an application does not use graphical APIs.
- Make the runtime explicit. Record the required Java major version in project documentation, CI configuration, container images, and systemd units.
- Set memory limits deliberately. Configure heap and container limits from measured workload behavior. Do not copy arbitrary
-Xmxvalues between hosts. - Keep secrets out of source code and command arguments. Use a protected secret store or service-specific credentials mechanism, and rotate exposed credentials.
- Monitor the process. Collect application metrics, structured logs, exit status, restart counts, garbage-collection behavior, and resource saturation.
For containers, pin a maintained base image by an appropriate version or digest, run as a non-root user, and rebuild regularly so operating-system and JDK fixes are included. A small image is useful, but reproducibility and timely updates matter more than size alone.
Frequently Asked Questions
Is Java 25 an LTS release?
OpenJDK 25 reached general availability in September 2025 and is an LTS release from most vendors. Support periods and commercial terms vary by distributor, so check the policy of the specific build used in production.
What is the difference between the JDK and JRE?
The JRE provides the virtual machine and libraries required to run Java applications. The JDK adds development tools such as javac. Install the JDK to build software and a headless JRE when a server only runs a prebuilt application.
Can Java 21 and Java 25 coexist on Ubuntu?
Yes. Ubuntu installs JDK releases into separate directories under /usr/lib/jvm. Use update-alternatives to select system defaults, or invoke a specific JDK by its full path for a project or service.
Is JAVA_HOME required on Ubuntu?
The Java launcher does not require JAVA_HOME when its executable is available on PATH. Some build tools, servers, and scripts do require it, so setting it explicitly prevents ambiguous runtime selection.
How do I uninstall Java 25?
Warning: removing a JDK can stop applications and build jobs that depend on it. Check dependencies and select another default Java version first. Then remove the package:
sudo apt remove openjdk-25-jdk
APT may suggest autoremove for unused dependencies. Review that proposed list carefully before approving it, especially on a shared development or production server.
Conclusion
The most maintainable way to install Java 25 on Ubuntu 24.04 is through the official openjdk-25-jdk package. Verify both java and javac, derive JAVA_HOME from the active binary, and keep runtime and compiler alternatives aligned. A compiled test program confirms that the complete toolchain works before you introduce Maven, Gradle, or a production application.