Skip to main content
How to Install Java 25 on Ubuntu Using apt-get - Virtarix Blog

How to Install Java 25 on Ubuntu Using apt-get

December 5, 2025 · Blog / Technical Guides

Java 25 introduces groundbreaking features such as primitive pattern matching, compact object headers, and enhanced virtual thread performance. Missing out on these improvements means slower applications and outdated code practices that put you behind the curve.

This comprehensive guide walks you through every step of installing Java 25 on Ubuntu. You will learn how to install via apt for supported versions, perform manual installation on older systems, configure multiple Java versions, set up JAVA_HOME correctly, and troubleshoot common installation issues. By the end, you will have a fully functional Java 25 environment ready for development or production deployment.

Critical: OpenJDK 25 is officially available via apt only on Ubuntu 25.04 and 25.10. Ubuntu 24.04 LTS and earlier versions require manual installation or OpenJDK 21.

Check your system

Before proceeding, verify your Ubuntu version and system architecture. This ensures you follow the correct installation method. Check Ubuntu version:

“`bash title="Show the Ubuntu release information" lsb_release -a


The output displays your distribution information. Note the Release field as this determines which method applies to you.

Check system architecture:

```bash title="Show the machine architecture"
uname -m

You will see x86_64 for Intel/AMD 64-bit systems or aarch64 for ARM 64-bit systems. This information is crucial when downloading Java packages manually.

Method A (Apt): Available only on Ubuntu 25.04 and 25.10. Provides automatic updates through the package manager.

Method B (Manual): Required for Ubuntu 20.04, 22.04, and 24.04 LTS. Requires manual update monitoring.

Recommended for production: Ubuntu LTS users should use OpenJDK 21 via apt for automatic security updates on production Linux VPS servers. This provides stability and seamless integration with Ubuntu's package management.

About Java 25

Java 25 includes several significant enhancements. Key features include primitive pattern matching (JEP 507, preview), compact object headers (JEP 519), flexible constructor bodies (JEP 513), module import declarations (JEP 511), and enhanced virtual thread synchronization.

Preview features: JEP 507 (Primitive Types in Patterns) is in preview status and requires the --enable-preview flag. Preview features may change in future releases. Use with caution in production:

“`bash title="Compile and run Java 25 preview features" javac –enable-preview –release 25 YourFile.java java –enable-preview YourClass


Preview features should be thoroughly tested before production use. Always prefer finalized features for critical applications.

For production environments on Ubuntu LTS versions, OpenJDK 21 remains the optimal choice. It offers excellent stability, automatic security updates, and is officially supported on all current LTS releases.

## Prerequisites

Update your package lists to ensure access to the latest available software:

```bash title="Refresh the APT package index"
sudo apt update

If Java is already installed, back up your current version information:

“`bash title="Save the current Java version output" java -version > ~/java-version-backup.txt


This backup helps you quickly revert if needed.

## Method one: install with apt on Ubuntu 25.04 and 25.10

This method works exclusively on Ubuntu 25.04 (Plucky Puffin) and Ubuntu 25.10 (Questing Quokka). These are the only versions with officially documented OpenJDK 25 packages.

Skip this section if running Ubuntu 24.04 or earlier.

### Install the Java development kit

The JDK includes the compiler, debugger, and all development tools:

```bash title="Install the OpenJDK 25 development kit"
sudo apt install openjdk-25-jdk

Need a reliable Ubuntu VPS for this Java 25 runtime?

After Java installs cleanly, run the workload on a Virtarix Ubuntu VPS with root access, NVMe storage, snapshots, backups, and room to move from test commands to real services.

The package manager displays download size and disk space requirements. Press Y and Enter to confirm.

Install only the runtime environment

For production systems running Java applications without development needs:

“`bash title="Install the OpenJDK 25 runtime" sudo apt install openjdk-25-jre


The JRE is smaller and excludes development tools, making it suitable for Linux VPS production deployments.

### Verify installation

Check Java runtime version:

```bash title="Show the Java runtime version"
java -version

For JDK installations, verify the compiler:

“`bash title="Show the Java compiler version" javac -version


Both commands should display Java 25 version information.

## Method two: manual installation for Ubuntu 20.04/22.04/24.04

For Ubuntu LTS versions where OpenJDK 25 is not available through apt, you have two options.

**Ubuntu 24.04 LTS note:** OpenJDK 25 is not officially documented or supported. Use OpenJDK 21 for production Linux VPS environments. Follow manual installation only for development or testing.

### Option 1: use OpenJDK 21 (recommended)

For production environments, OpenJDK 21 provides the ideal balance:

```bash title="Install the OpenJDK 21 development kit"
sudo apt install openjdk-21-jdk

OpenJDK 21 is an LTS release receiving automatic security updates via Ubuntu's unattended-upgrades system. This eliminates manual monitoring requirements.

Option 2: manual installation of Java 25

Follow these steps to manually install Java 25. This gives you access to the latest features but requires manual update management.

Check available disk space:

“`bash title="Check free space under the opt directory" df -h /opt


Ensure you have at least 500 MB free space.

Download Java 25 for your architecture:

```bash title="Download Java 25 archives for x86_64 and ARM64"
cd ~/Downloads
## For x86_64 systems:
wget https://download.oracle.com/java/25/latest/jdk-25_linux-x64_bin.tar.gz
## For aarch64 systems:
wget https://download.oracle.com/java/25/latest/jdk-25_linux-aarch64_bin.tar.gz

Note: This URL automatically downloads the latest Java 25 update. The actual version may be 25.0.1 or later.

Extract the archive:

“`bash title="Extract the x8664 Java 25 archive into opt" sudo mkdir -p /opt/jdk sudo tar -xzf jdk-25linux-x64_bin.tar.gz -C /opt/jdk


Check the exact directory name:

```bash title="List the extracted JDK directories"
ls /opt/jdk/

You will see a directory like jdk-25 or jdk-25.0.1. Note this exact name.

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

“`bash title="Register Java 25 binaries with alternatives" sudo update-alternatives –install /usr/bin/java java /opt/jdk/jdk-25/bin/java 1 sudo update-alternatives –install /usr/bin/javac javac /opt/jdk/jdk-25/bin/javac 1


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

```bash title="Select the default Java runtime and compiler"
sudo update-alternatives --config java
sudo update-alternatives --config javac

Select the Java 25 option for both commands.

Verify installation:

“`bash title="Verify matching Java and javac versions" java -version javac -version


Both should display matching Java 25 version information.

## Alternative Java distributions

Besides Oracle JDK and OpenJDK, consider these production-ready alternatives:

- [**Eclipse Temurin**](https://adoptium.net/) (Adoptium) provides high-quality OpenJDK binaries with active community support.
- [**Azul Zulu**](https://www.azul.com/downloads/) provides fully tested OpenJDK builds with commercial support options.
- [**Amazon Corretto**](https://aws.amazon.com/corretto/) is Amazon's distribution with long-term support and performance optimizations.
- [**Microsoft Build of OpenJDK**](https://learn.microsoft.com/en-us/java/openjdk/) offers binaries optimized for Azure environments.

All provide LTS support and regular security updates suitable for production use.

## Understanding JDK versus JRE

**Java Development Kit (JDK)** includes a compiler, debugger, development tools, and the complete runtime environment. Install on development machines. **Java Runtime Environment (JRE)** includes only the JVM and libraries needed to run applications. Install on production systems running precompiled applications. This reduces disk space and minimizes the attack surface.

## Managing multiple versions

Ubuntu systems can run multiple Java versions simultaneously. This proves valuable when testing compatibility or when different applications require specific versions.

List installed versions:

```bash title="List the installed Java runtime alternatives"
update-alternatives --list java

This displays file paths for each installed version.

Switch between versions interactively:

“`bash title="Select the active Java runtime and compiler" sudo update-alternatives –config java sudo update-alternatives –config javac


The system presents a numbered list. An asterisk marks the active version.

**Critical:** Always set both `java` and `javac` to the same version. Mismatched versions cause runtime and compilation errors.

Switch all Java components simultaneously:

```bash title="Set all Java components to a Java 25 alternative"
sudo update-java-alternatives --list
sudo update-java-alternatives --set java-1.25.0-openjdk-amd64

Replace the version identifier with the name from your list.

Setting 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:

“`bash title="Display the Java runtime alternatives configuration" 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:

```bash title="List the manually installed JDK directories"
ls /opt/jdk/

System-wide configuration

Edit the system environment file:

“`bash title="Open the system environment file" sudo nano /etc/environment


Add this line (adjust path to your installation):

```conf title="Set JAVA_HOME for APT-installed Java 25"
JAVA_HOME="/usr/lib/jvm/java-25-openjdk-amd64"

For manual installations:

“`conf title="Set JAVAHOME for manually installed Java 25" JAVAHOME="/opt/jdk/jdk-25"


Use the exact directory name from your installation. Save (`Ctrl+O`, `Enter`) and exit (`Ctrl+X`).

Apply changes:

```bash title="Reload the system environment and print JAVA_HOME"
source /etc/environment
echo $JAVA_HOME

The echo command confirms proper configuration.

User-specific configuration

To set JAVA_HOME only for your user account:

“`bash title="Open the Bash user configuration" nano ~/.bashrc


Add these lines:

```bash title="Export JAVA_HOME and extend PATH"
export JAVA_HOME="/usr/lib/jvm/java-25-openjdk-amd64"
export PATH=$PATH:$JAVA_HOME/bin

Apply immediately:

“`bash title="Reload the Bash configuration and print JAVAHOME" source ~/.bashrc echo $JAVAHOME


This method isolates the configuration to your account without affecting other users.

## Troubleshooting common issues

### Unable to locate package error

This error indicates OpenJDK 25 is not available in your repositories.

**For Ubuntu 20.04, 22.04, or 24.04 LTS:** OpenJDK 25 is not available via apt. Use OpenJDK 21:

```bash title="Install OpenJDK 21 on Ubuntu LTS"
sudo apt install openjdk-21-jdk

Alternatively, follow the manual installation method.

For Ubuntu 25.04 or 25.10: Update your package lists:

“`bash title="Refresh the APT package index" sudo apt update


Then retry the installation.

### Package has no installation candidate

Update repository information:

```bash title="Search APT for available OpenJDK packages"
sudo apt update
apt search openjdk

Review available versions and install the highest LTS version for your release.

Wrong Java version running

If the incorrect version runs despite configuration changes:

“`bash title="Find the active Java and javac executables" which java which javac


Both should point to `/usr/bin/java` and `/usr/bin/javac`. Reconfigure alternatives:

```bash title="Choose matching Java and javac alternatives"
sudo update-alternatives --config java
sudo update-alternatives --config javac

Select the same version for both.

Java_HOME not recognized

If applications cannot find JAVA_HOME:

“`bash title="Inspect JAVAHOME and its Java executable" ls $JAVAHOME/bin/java echo $JAVA_HOME


Reload your environment:

```bash title="Reload the system environment"
source /etc/environment

For user configurations:

“`bash title="Reload the Bash user configuration" source ~/.bashrc


If issues persist, log out and back in.

### Permission denied for manual installation

Adjust directory ownership and permissions:

> **Safety check:** Confirm the target and keep a recent backup or snapshot. Preview the affected resources where possible, and document a tested recovery or rollback path before running this command.

```bash title="Set the JDK directory ownership and permissions"
sudo chmod -R 755 /opt/jdk/jdk-25
sudo chown -R root:root /opt/jdk/jdk-25

Uninstalling Java

APT installation removal

“`bash title="Remove the OpenJDK 25 packages" sudo apt remove openjdk-25-jdk openjdk-25-jre sudo apt purge openjdk-25-jdk openjdk-25-jre sudo apt autoremove


### Manual installation removal

> **Safety check:** Confirm the target and keep a recent backup or snapshot. Preview the affected resources where possible, and document a tested recovery or rollback path before running this command.

```bash title="Remove manually installed Java 25 and its alternatives"
sudo rm -rf /opt/jdk/jdk-25
sudo update-alternatives --remove java /opt/jdk/jdk-25/bin/java
sudo update-alternatives --remove javac /opt/jdk/jdk-25/bin/javac

Decision guide for choosing Java version

Use OpenJDK 21 via apt if:

  • Running Ubuntu 20.04, 22.04, or 24.04 LTS
  • Operating production environments
  • Need automatic security updates
  • Want proven stability

Use OpenJDK 25 via apt if:

  • Running Ubuntu 25.04 or 25.10
  • Need the latest Java features
  • Working in development or testing
  • Comfortable with preview features

Use manual Java 25 installation if:

  • Running Ubuntu 24.04 or earlier
  • Testing new Java 25 features
  • Need a specific version for development
  • Willing to monitor updates manually

Verification and testing

After installation, perform comprehensive verification.

Test basic functionality:

“`bash title="Verify the Java toolchain and JAVAHOME" java -version javac -version echo $JAVAHOME which java


Compile and run a test program:

```bash title="Compile and run a Java 25 test program"
echo 'public class Test { public static void main(String[] args) { System.out.println("Java 25 works!"); } }' > Test.java
javac Test.java
java Test
rm Test.java Test.class

Expected output: "Java 25 works!"

This confirms your installation can compile and execute programs successfully.

Conclusion

OpenJDK 25 is an LTS release from many vendors. The support period depends on the distribution or vendor you install, so confirm its lifecycle before choosing a production package.

Ubuntu 25.04 and 25.10: Install via apt for automatic updates and simple management.

Ubuntu 24.04 LTS: OpenJDK 25 is not officially supported. Use OpenJDK 21 via apt for production systems. Manual installation available for development and testing.

Ubuntu 20.04 and 22.04 LTS: Use OpenJDK 21 via apt for production stability. Manual installation for development only.

For production environments on Ubuntu LTS releases, OpenJDK 21 provides optimal stability with automatic security patches delivered through unattended-upgrades. This ensures your Java environment remains secure without manual intervention.

Ready to run Java 25 on a Virtarix Ubuntu VPS?

Start small for Java development or choose more headroom for staging and production services. Both options include root access, NVMe storage, IPv4 + IPv6, snapshots, and backups.

VPS S

For small sites, dev servers and Docker

$ 5 .50 /month
  • 3 cores
  • 6 GB
  • 50 GB NVMe
  • Unlimited
Get It Now
BEST SELLER

VPS M

For growing apps, websites and staging

$ 11 .40 /month
  • 6 cores
  • 16 GB
  • 100 GB NVMe
  • Unlimited
Get It Now
Peter French
About the Author Peter Frenchis the Managing Director at Virtarix, with over 17 years in the tech industry. He has co-founded a cloud storage business, led strategy at a global cloud computing leader, and driven market growth in cybersecurity and data protection.