Java is one of the most widely used programming languages, integrated into web, desktop, and mobile apps. To run Java applications on Ubuntu 24.04, you need the JRE (Java Runtime Environment), which is included in the JDK (Java Development Kit).

You can use OpenJDK (open-source, recommended for most users) or Oracle JDK (closed-source, subscription-based) to run or develop Java apps on Ubuntu 24.04.

Quick answer

The fastest way is APT: sudo apt install default-jre -y installs the Java runtime, and sudo apt install default-jdk -y adds the compiler. Both pull OpenJDK from Ubuntu’s official repositories with no manual setup required.

How to Install Java on Ubuntu 24.04

Method Java edition Best for
APT (default-jre / default-jdk) OpenJDK (Ubuntu-packaged) Quick setup, most users
Oracle deb file Oracle JDK 17+ Specific Oracle JDK version needed
tar.gz (wget) Oracle JDK 22+ Portable install without apt

Method 1: Install Java on Ubuntu 24.04 Using the apt Command

Install the Java runtime from Ubuntu’s official repositories:

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

Verify the installation:

java -version
Terminal output of java -version showing installed JRE on Ubuntu 24.04

To also install the JDK for compiling Java programs:

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

Verify the JDK:

javac -version
Terminal output of javac -version showing JDK version on Ubuntu 24.04

Method 2: Install Java on Ubuntu 24.04 Using the .deb File

The Oracle JDK deb file gives you the official Oracle Java build. Download it with wget (replace 17 with your target version):

wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.deb
Terminal output of wget downloading Oracle JDK deb package on Ubuntu 24.04

Install the deb file:

sudo dpkg -i jdk-17_linux-x64_bin.deb
Terminal output of sudo dpkg -i jdk-17 deb file on Ubuntu 24.04

Verify. If you see an Exec format error, the deb was compiled for a different CPU architecture:

java -version
Terminal output of java -version showing Exec format error on Ubuntu 24.04

If you get that error, first check your CPU architecture:

lscpu
Terminal output of lscpu showing CPU architecture on Ubuntu 24.04

Then list available Java alternatives and note the path matching your CPU architecture:

sudo update-alternatives --config java
Terminal showing sudo update-alternatives --config java on Ubuntu 24.04

Open /etc/environment and add JAVA_HOME="/your/java/path":

sudo nano /etc/environment
Nano editor showing JAVA_HOME set in /etc/environment on Ubuntu 24.04

Apply the changes and verify:

source /etc/environment
java -version
Terminal output of java -version after fixing Exec format error on Ubuntu 24.04

Method 3: Install Java on Ubuntu 24.04 Using the Tar File

The tar.gz approach gives you a portable Oracle JDK install with no apt involvement. Download the JDK tar.gz (for x86_64 systems, replace aarch64 with x64 in the filename):

wget https://download.oracle.com/java/22/latest/jdk-22_linux-aarch64_bin.tar.gz
Terminal output of wget downloading JDK 22 tar.gz on Ubuntu 24.04

Extract the archive:

sudo tar -xvf jdk-22_linux-aarch64_bin.tar.gz
Terminal output of tar -xvf extracting JDK tar.gz on Ubuntu 24.04

Open ~/.bashrc and add these two lines at the bottom:

sudo nano ~/.bashrc
Nano editor showing JAVA_HOME and PATH export in ~/.bashrc on Ubuntu 24.04
export JAVA_HOME=/home/user/jdk-22
export PATH=$JAVA_HOME/bin:$PATH

Apply the changes:

source ~/.bashrc

How to Uninstall Java From Ubuntu 24.04

Install method Remove command
APT (default-jre / default-jdk) sudo apt purge default-jre default-jdk && sudo apt autoremove
Oracle deb (dpkg) sudo dpkg -r jdk-17 (replace with installed version)
tar.gz sudo rm -rf ~/jdk-22 then remove JAVA_HOME lines from ~/.bashrc

Related Ubuntu 24.04 guides