Oracle JDK is the official Java Development Kit from Oracle, used for building and running Java applications. While OpenJDK covers most use cases, Oracle JDK includes commercial features, longer support cycles, and performance optimizations that some enterprise environments require.
This guide covers multiple ways to install Java on Ubuntu 24.04 and Debian 13 – from the simplest OpenJDK route for general use, to Oracle JDK via .deb package or tarball for specific requirements. We also cover managing multiple Java versions side by side using update-alternatives. Oracle JDK 25 is the current Long-Term Support (LTS) release, supported by Oracle through September 2033.
Prerequisites
Before starting, make sure you have the following in place:
- Ubuntu 24.04 LTS or Debian 13 server/desktop with root or sudo access
- At least 1 GB of free disk space for JDK installation
- Internet connectivity to download packages
wgetorcurlinstalled for downloading Oracle JDK
Update your system packages before proceeding:
sudo apt update && sudo apt upgrade -y
Step 1: Install OpenJDK (Recommended for Most Users)
OpenJDK is the open-source implementation of the Java Platform and ships directly in Ubuntu and Debian repositories. For most development and production workloads, OpenJDK works identically to Oracle JDK. Unless you need Oracle-specific commercial features or support, start here.
Install OpenJDK 21 (the current LTS version in distro repos) with a single command:
sudo apt install -y openjdk-21-jdk
If you only need the runtime (no compiler), install the JRE instead:
sudo apt install -y openjdk-21-jre
Confirm the installation by checking the Java version:
java -version
The output confirms OpenJDK 21 is active:
openjdk version "21.0.6" 2025-01-21
OpenJDK Runtime Environment (build 21.0.6+7-Ubuntu-1ubuntu24.04)
OpenJDK 64-Bit Server VM (build 21.0.6+7-Ubuntu-1ubuntu24.04, mixed mode, sharing)
For projects that specifically require a different Java version, you can install multiple OpenJDK versions and switch between them. Other available versions include openjdk-17-jdk and openjdk-11-jdk.
Step 2: Install Oracle JDK 25 from .deb Package
Oracle provides official .deb packages that integrate cleanly with the system package manager. This is the easiest way to install Oracle JDK on Ubuntu or Debian. Oracle JDK 25.0.2 is the latest LTS release at the time of writing.
Download the Oracle JDK 25 .deb package directly from Oracle’s official downloads page:
wget https://download.oracle.com/java/25/latest/jdk-25_linux-x64_bin.deb
Install the downloaded package using dpkg:
sudo dpkg -i jdk-25_linux-x64_bin.deb
The .deb package installs Oracle JDK to /usr/lib/jvm/jdk-25-oracle-x64 and automatically registers itself with the alternatives system. Verify the installation:
/usr/lib/jvm/jdk-25-oracle-x64/bin/java -version
You should see Oracle JDK 25.0.2 confirmed:
java version "25.0.2" 2025-10-14
Java(TM) SE Runtime Environment (build 25.0.2+7-jdk-25.0.2-ga)
Java HotSpot(TM) 64-Bit Server VM (build 25.0.2+7-jdk-25.0.2-ga, mixed mode, sharing)
Clean up the downloaded package:
rm -f jdk-25_linux-x64_bin.deb
Step 3: Install Oracle JDK 25 from Tarball
The tarball method gives you full control over the installation directory. This approach works well when you need multiple JDK versions installed side by side, or when you want Java in a non-standard location.
Download the Oracle JDK 25 tarball:
wget https://download.oracle.com/java/25/latest/jdk-25_linux-x64_bin.tar.gz
Create a directory for Java installations and extract the archive:
sudo mkdir -p /usr/lib/jvm
sudo tar -xzf jdk-25_linux-x64_bin.tar.gz -C /usr/lib/jvm
The JDK extracts to /usr/lib/jvm/jdk-25.0.2. Verify it:
/usr/lib/jvm/jdk-25.0.2/bin/java -version
The output should show Oracle JDK 25.0.2:
java version "25.0.2" 2025-10-14
Java(TM) SE Runtime Environment (build 25.0.2+7-jdk-25.0.2-ga)
Java HotSpot(TM) 64-Bit Server VM (build 25.0.2+7-jdk-25.0.2-ga, mixed mode, sharing)
Register the tarball installation with the alternatives system so it can be managed alongside other JDK versions:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-25.0.2/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-25.0.2/bin/javac 1
sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk-25.0.2/bin/jar 1
Clean up the downloaded archive:
rm -f jdk-25_linux-x64_bin.tar.gz
Step 4: Configure JAVA_HOME Environment Variable
Many Java-based tools – Apache Maven, Gradle, Tomcat, and others – rely on the JAVA_HOME environment variable to locate the JDK. Setting this correctly prevents build errors and runtime failures.
First, find the path of your active Java installation:
readlink -f $(which java) | sed 's|/bin/java||'
This returns the full path to your active JDK, for example /usr/lib/jvm/jdk-25.0.2 or /usr/lib/jvm/java-21-openjdk-amd64.
Set JAVA_HOME permanently by adding it to your shell profile. Open the file:
sudo vi /etc/profile.d/java.sh
Add the following lines (adjust the path based on the output from the previous command):
export JAVA_HOME=/usr/lib/jvm/jdk-25.0.2
export PATH=$JAVA_HOME/bin:$PATH
For OpenJDK, use the corresponding path instead:
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
Load the new environment variable in your current session:
source /etc/profile.d/java.sh
Verify JAVA_HOME is set correctly:
echo $JAVA_HOME
The output should show your JDK path:
/usr/lib/jvm/jdk-25.0.2
Step 5: Manage Multiple Java Versions with update-alternatives
When you have both OpenJDK and Oracle JDK installed, or multiple JDK versions, the update-alternatives system lets you switch the default Java version cleanly. This is common in development environments where different projects require different JDK versions.
List all installed Java versions registered with the alternatives system:
sudo update-alternatives --list java
This shows every Java binary registered on your system:
/usr/lib/jvm/java-21-openjdk-amd64/bin/java
/usr/lib/jvm/jdk-25.0.2/bin/java
To switch between versions interactively, run:
sudo update-alternatives --config java
You see a numbered list of available Java installations. Enter the number corresponding to the version you want as default:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-21-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-21-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/jdk-25.0.2/bin/java 1 manual mode
Press to keep the current choice[*], or type selection number:
Do the same for javac (the Java compiler) and jar to keep them in sync:
sudo update-alternatives --config javac
sudo update-alternatives --config jar
After switching, remember to update JAVA_HOME in /etc/profile.d/java.sh to match the newly selected version. Read our dedicated guide on setting the default Java version on Ubuntu and Debian for more details.
Step 6: Verify Java Installation
After installation and configuration, run these verification checks to confirm everything works correctly.
Check the Java runtime version:
java -version
Check the Java compiler version:
javac -version
The compiler output confirms the JDK (not just JRE) is installed:
javac 25.0.2
Verify JAVA_HOME is set and points to the right directory:
echo $JAVA_HOME
Run a quick test to confirm Java can compile and execute code. Create a simple test file:
echo 'public class Test { public static void main(String[] args) { System.out.println("Java is working - " + System.getProperty("java.version")); } }' > /tmp/Test.java
Compile and run the test:
javac /tmp/Test.java -d /tmp && java -cp /tmp Test
You should see the Java version printed, confirming both the compiler and runtime are working:
Java is working - 25.0.2
Clean up the test files:
rm -f /tmp/Test.java /tmp/Test.class
Step 7: Oracle JDK vs OpenJDK – Which One to Use
Oracle JDK and OpenJDK share the same codebase, but there are practical differences that affect which one you should choose. Here is a direct comparison based on production experience.
| Feature | OpenJDK | Oracle JDK |
|---|---|---|
| License | GPL v2 with Classpath Exception – free for all use | Free for production under NFTC license (JDK 25+), paid support optional |
| Source Code | Fully open source at openjdk.org | Based on OpenJDK with additional Oracle tooling |
| LTS Support | Community-driven, varies by distributor | Oracle provides LTS with extended support through 2033 for JDK 25 |
| Performance | Identical for most workloads | Includes GraalVM JIT compiler and Oracle-specific optimizations |
| Updates | Available through system package manager | Manual download from Oracle or Oracle Linux repos |
| Best For | General development, CI/CD, containers, most production use | Enterprise environments needing Oracle support, specific Oracle tooling |
For most developers and system administrators, OpenJDK is the right choice. It is free, receives regular security updates through your distribution’s package manager, and performs identically to Oracle JDK for standard workloads. Choose Oracle JDK when your organization requires Oracle commercial support, needs the extended LTS timeline, or uses Oracle-specific features like advanced monitoring tools included in the JDK.
Conclusion
You now have Java installed on Ubuntu 24.04 or Debian 13 – whether through the quick OpenJDK package manager route or Oracle JDK via .deb package or tarball. The update-alternatives system makes switching between multiple versions straightforward when different projects have different requirements.
For production deployments, set up automatic security updates for OpenJDK through unattended-upgrades, or subscribe to Oracle’s security alert notifications if using Oracle JDK. Monitor the Oracle Java SE support roadmap to plan version migrations ahead of end-of-support dates.