Linux

How to Install Java on Ubuntu 24.04 Easily in 2026

Java remains one of the most widely used programming platforms for servers, enterprise applications, Android development, and modern build tools. If you want to install Java Ubuntu systems correctly, Ubuntu 24.04 provides several reliable options including OpenJDK and Oracle JDK.

This guide explains how to install Java on Ubuntu 24.04, switch between multiple Java versions, and configure the JAVA_HOME variable for development environments.

Why Java Is Important on Ubuntu

Many developers rely on Java for frameworks like Spring Boot, Gradle, Maven, and Apache Tomcat. Ubuntu 24.04 supports multiple Java releases, making it easier to run both older and modern applications without compatibility issues.

The two most common Java implementations are:

  • OpenJDK
  • Oracle JDK

OpenJDK is open-source and comes directly from Ubuntu repositories, while Oracle JDK is maintained by Oracle with separate licensing terms.

Install Java Ubuntu Using OpenJDK

Before installation, check whether Java is already available on your system:

java -version

If Java is missing, update your package index first:

sudo apt update

Ubuntu 24.04 includes OpenJDK packages directly through its repositories. To install the latest OpenJDK version, run:

sudo apt install openjdk-25-jdk

Once installed, verify the setup:

java -version

You should now see the installed Java version displayed in the terminal.

Install Java 21 on Ubuntu 24.04

Some applications still depend on Java 21 for long-term compatibility. Ubuntu’s default Java package uses this version.

Install it with:

sudo apt install default-jdk

You can also manually install Java 21:

sudo apt install openjdk-21-jdk

This option is ideal for projects that are not yet optimized for newer Java releases.

How to Install Oracle JDK

If your application specifically requires Oracle Java, download the official Debian package from Oracle’s website.

After downloading the .deb file, install it using:

sudo apt install ./jdk-25_linux-x64_bin.deb

Oracle JDK is commonly used in enterprise environments where vendor-specific support is required.

Switching Between Multiple Java Versions

If multiple Java versions are installed, Ubuntu allows you to choose the default version easily.

Run:

sudo update-alternatives --config java

You will see a list of installed Java versions. Select the preferred version number and press Enter.

Verify the change with:

java -version

Setting JAVA_HOME in Ubuntu

Many Java applications require the JAVA_HOME environment variable.

Open the environment configuration file:

sudo nano /etc/environment

Add your Java installation path:

JAVA_HOME="/usr/lib/jvm/java-25-openjdk-amd64"

Apply the changes:

source /etc/environment

Confirm the variable is working:

echo $JAVA_HOME

Final Thoughts

Learning how to install Java Ubuntu systems properly helps developers avoid compatibility issues and simplifies project setup. OpenJDK remains the best option for most users, while Oracle JDK is useful for enterprise workloads and vendor-supported deployments.

Ubuntu 24.04 makes Java management straightforward with flexible installation methods, version switching tools, and easy environment configuration.

Cyber Defence

Recent Posts

Bash Scripting Best Practices Every Beginner Should Know

Introduction Bash scripting is a powerful way to automate Linux tasks, but writing a script…

1 day ago

How To Create A Self-Signed SSL Certificate Using Bash And OpenSSL

Introduction A self-signed SSL certificate is a certificate that is created and signed by the…

1 day ago

How To Debug Bash Scripts Using bash -x And set Commands

Introduction Debugging is an important part of Bash scripting. When a script does not work…

1 day ago

How To Use Cron Jobs With Bash Scripts For Automation

Introduction Cron jobs are used in Linux to run commands or Bash scripts automatically at…

1 day ago

How To Use Pipes In Bash Scripts For Command Chaining

Introduction Pipes are an important feature in Linux and Bash scripting. A pipe allows you…

1 day ago

How To Use grep, awk, And sed In Bash Scripts

Introduction The grep, awk, and sed commands are powerful text-processing tools in Linux. They are…

2 days ago