Java is a popular programming language used to develop mobile and desktop applications. Java does not come pre-installed on Ubuntu. However, you can install Java on Ubuntu Linux manually through the default repository or directly from the Oracle platform. Java has three core components: JDK (Java Development Kit), JRE (Java Runtime Environment), and JVM (Java Virtual Machine). JDK is used to develop applications, JRE runs Java-based applications, and JVM executes Java programs.
Quick answer
The easiest way to install Java on Ubuntu 24.04 is through Ubuntu’s default repository, usually with OpenJDK. If a project needs Oracle Java or a specific Java release, install that version and then set the default with update-alternatives.
How to Install Java on Ubuntu 24.04
| Method | Source | Auto-updates | Best for |
|---|---|---|---|
| APT (default-jdk) | Ubuntu repository | Yes (apt upgrade) | Most users |
| Oracle deb package | oracle.com | No | Specific Oracle JDK version |
| App Center | Oracle deb via GUI | No | GUI-preferred install |
Method 1: Install Java on Ubuntu from the Default APT Repository
Ubuntu includes Java in its APT repository, which makes installation straightforward and guarantees a stable version that is easy to upgrade.
Step 1: Update System Packages
sudo apt update && sudo apt upgrade

Step 2: Install Java (JDK)
Install the default JDK, which includes JRE and JVM:
sudo apt install -y default-jdk

To install only JRE (without developer tools):
sudo apt install -y default-jre

Step 3: Verify the Java Version
java --version

Check the Java compiler version:
javac --version

Method 2: Install Java on Ubuntu Using the Oracle Deb Package
Download the Oracle JDK deb package directly from Oracle’s website to get a specific JDK version or the latest Oracle Java release.
Step 1: Download the Java Deb Package
Browse the official Java website, locate the Linux x64 Debian Package, and download it with wget:
wget https://download.oracle.com/java/21/archive/jdk-21.0.2_linux-x64_bin.deb

Step 2: Install the Oracle JDK
sudo apt install ./jdk-21.0.2_linux-x64_bin.deb

Note: If you downloaded the deb package from a browser, it will be in your Downloads folder. Install it with:
sudo apt install ./Downloads/jdk-21.0.2_linux-x64_bin.deb
Method 3: Install Java on Ubuntu Using App Center
You can also install Java through App Center using the Oracle deb package without using the terminal.
Step 1: Download the Java Deb Package from the Browser
Navigate to the Java website and download the Linux x64 Debian Package:

Step 2: Open the Deb Package with App Center
Open the Downloads folder and locate the JDK deb package:

Right-click the deb file and select Open With App Center:

Click the Install button and enter your credentials when prompted to complete the installation.
How to Install a Specific Java Version on Ubuntu 24.04
To see all available OpenJDK versions in Ubuntu’s repository:
sudo apt search "OpenJDK"

Install the version you need (replace 21 with your required version number):
sudo apt install -y openjdk-21-jdk

How to Set the Default Java Version on Ubuntu 24.04
Step 1: Check the Current Default Version
java --version

Step 2: Switch the Default Java Version
Run the following command to list all installed Java versions. Enter the number for the version you want and press Enter:
sudo update-alternatives --config java

Step 3: Verify the Change
java --version

How to Uninstall Java from Ubuntu 24.04
| What to remove | Command |
|---|---|
| Default JDK and JRE | sudo apt remove -y default-jdk |
| Specific OpenJDK version | sudo apt remove -y openjdk-21-jdk |
| All Java packages | sudo apt autoremove java* -y |
sudo apt remove -y default-jdk

To remove a specific OpenJDK version:
sudo apt remove -y openjdk-21-jdk

To completely remove all Java packages:
sudo apt autoremove java* -y

Before choosing a Java version
Most Ubuntu users should start with OpenJDK from the default repository because it is simple to update and works for common Java applications, build tools, and development tasks.
Use a specific Oracle or OpenJDK version only when an application requires it. After installing more than one Java version, confirm the active version with java -version before troubleshooting the app itself.