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:
lsb_release -a
The output displays your distribution information. Note the Release field as this determines which method applies to you.
Check system 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 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:
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:
sudo apt update
If Java is already installed, back up your current version information:
java -version > ~/java-version-backup.txt
This backup helps you quickly revert if needed.
Method A: Apt Installation for 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:
sudo apt install openjdk-25-jdk
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:
sudo apt install openjdk-25-jre
The JRE is smaller and excludes development tools, making it suitable for production deployments.
Verify Installation
Check Java runtime version:
java -version
For JDK installations, verify the compiler:
javac -version
Both commands should display Java 25 version information.
Method B: 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 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:
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:
df -h /opt
Ensure you have at least 500 MB free space.
Download Java 25 for your architecture:
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:
sudo mkdir -p /opt/jdk
sudo tar -xzf jdk-25_linux-x64_bin.tar.gz -C /opt/jdk
Check the exact directory name:
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:
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:
sudo update-alternatives --config java
sudo update-alternatives --config javac
Select the Java 25 option for both commands.
Verify installation:
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 (Adoptium) provides high-quality OpenJDK binaries with active community support.
- Azul Zulu provides fully tested OpenJDK builds with commercial support options.
- Amazon Corretto is Amazon’s distribution with long-term support and performance optimizations.
- Microsoft Build of 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:
update-alternatives --list java
This displays file paths for each installed version.
Switch between versions interactively:
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:
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:
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:
ls /opt/jdk/
System-Wide Configuration
Edit the system environment file:
sudo nano /etc/environment
Add this line (adjust path to your installation):
JAVA_HOME="/usr/lib/jvm/java-25-openjdk-amd64"
For manual installations:
JAVA_HOME="/opt/jdk/jdk-25"
Use the exact directory name from your installation. Save (Ctrl+O, Enter) and exit (Ctrl+X).
Apply changes:
source /etc/environment
echo $JAVA_HOME
The echo command confirms proper configuration.
User-Specific Configuration
To set JAVA_HOME only for your user account:
nano ~/.bashrc
Add these lines:
export JAVA_HOME="/usr/lib/jvm/java-25-openjdk-amd64"
export PATH=$PATH:$JAVA_HOME/bin
Apply immediately:
source ~/.bashrc
echo $JAVA_HOME
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:
sudo apt install openjdk-21-jdk
Alternatively, follow the manual installation method.
For Ubuntu 25.04 or 25.10: Update your package lists:
sudo apt update
Then retry the installation.
Package Has No Installation Candidate
Update repository information:
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:
which java
which javac
Both should point to /usr/bin/java and /usr/bin/javac. Reconfigure 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:
ls $JAVA_HOME/bin/java
echo $JAVA_HOME
Reload your environment:
source /etc/environment
For user configurations:
source ~/.bashrc
If issues persist, log out and back in.
Permission Denied for Manual Installation
Adjust 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
sudo apt remove openjdk-25-jdk openjdk-25-jre
sudo apt purge openjdk-25-jdk openjdk-25-jre
sudo apt autoremove
Manual Installation Removal
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:
java -version
javac -version
echo $JAVA_HOME
which java
Compile and run a 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
Java 25 is the latest LTS release with support planned until at least September 2033. The installation approach depends on your Ubuntu version.
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.
