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
Terminal output of sudo apt update and upgrade on Ubuntu 24.04

Step 2: Install Java (JDK)

Install the default JDK, which includes JRE and JVM:

sudo apt install -y default-jdk
Terminal output of sudo apt install default-jdk on Ubuntu 24.04

To install only JRE (without developer tools):

sudo apt install -y default-jre
Terminal output of sudo apt install default-jre on Ubuntu 24.04

Step 3: Verify the Java Version

java --version
Terminal output of java --version showing Java version on Ubuntu 24.04

Check the Java compiler version:

javac --version
Terminal output of javac --version showing Java compiler version on Ubuntu 24.04

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
Terminal output of wget downloading Oracle JDK 21 deb on Ubuntu 24.04

Step 2: Install the Oracle JDK

sudo apt install ./jdk-21.0.2_linux-x64_bin.deb
Terminal output of sudo apt install Oracle JDK 21 deb on Ubuntu 24.04

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:

Oracle Java website showing Linux x64 Debian Package download link

Step 2: Open the Deb Package with App Center

Open the Downloads folder and locate the JDK deb package:

File manager showing Oracle JDK deb package in Downloads folder on Ubuntu 24.04

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

File manager context menu showing Open With App Center for JDK deb on Ubuntu 24.04

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"
Terminal output of apt search OpenJDK listing available Java versions on Ubuntu 24.04

Install the version you need (replace 21 with your required version number):

sudo apt install -y openjdk-21-jdk
Terminal output of sudo apt install openjdk-21-jdk on Ubuntu 24.04

How to Set the Default Java Version on Ubuntu 24.04

Step 1: Check the Current Default Version

java --version
Terminal output of java --version showing current default Java on Ubuntu 24.04

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
Terminal output of sudo update-alternatives --config java on Ubuntu 24.04

Step 3: Verify the Change

java --version
Terminal output of java --version after changing default Java version on Ubuntu 24.04

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
Terminal output of sudo apt remove default-jdk on Ubuntu 24.04

To remove a specific OpenJDK version:

sudo apt remove -y openjdk-21-jdk
Terminal output of sudo apt remove specific Java version on Ubuntu 24.04

To completely remove all Java packages:

sudo apt autoremove java* -y
Terminal output of sudo apt autoremove java on Ubuntu 24.04

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.

Related Ubuntu 24.04 guides