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

Verify the installation:
java -version

To also install the JDK for compiling Java programs:
sudo apt install default-jdk -y

Verify the JDK:
javac -version

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

Install the deb file:
sudo dpkg -i jdk-17_linux-x64_bin.deb

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

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

Then list available Java alternatives and note the path matching your CPU architecture:
sudo update-alternatives --config java

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

Apply the changes and verify:
source /etc/environment
java -version

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

Extract the archive:
sudo tar -xvf jdk-22_linux-aarch64_bin.tar.gz

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

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 |