Install Java's JDK on Ubuntu

Whether you want to play a video game like Minecraft that requires the Java runtime environment, or you want to develop software with tools such as Maven, Jenkins or Eclipse that require the JDK, you need to install Java on your computer. Here's how to install the latest LTS Java release on Ubuntu.

How to install Java on Ubuntu

You can install Java's JDK on Ubuntu 24 with a single command:

sudo apt install default-jdk

This installs the latest LTS Java release into the /usr/lib/jvm folder. A directory listing of this folder shows both the default-java folder and a folder named openjdk-21:

ls /usr/lib/jvm
default-java java-21-openjdk-amd64

Ubuntu's JDK install folder

The default-java folder is a symbolic link to the actual location of the JDK install on Ubuntu.

When you reference the JDK install location in applications or in environment variables such as JAVA_HOME, the use of the symbolic link makes your configuration more flexible and adaptable. If you install a new version of Java on Ubuntu, you simply update the symbolic link and this will update all programs on your system that use it to the updated version as well.

Update Ubuntu's JAVA_HOME

After you install Java and the JDK on Ubuntu, it's customary to set the JAVA_HOME environment variable as well. To do this, simply edit the user's environment configuration with the following command:

sudo nano /etc/environment.d/90java.conf

Then point the JAVA_HOME environment variable to the symbolic link with the following entry:

JAVA_HOME="usr/lib/jvm/default-java"

Reload your Ubuntu environment

Refresh your environment and you'll be able to successfully echo the JAVA_HOME variable:

source /etc/environment.d/90java.conf
echo $JAVA_HOME

usr/lib/jvm/default-java

With Java installed on Ubuntu and the JAVA_HOME environment variable properly configured, you're ready to start using and enjoying all your favorite Java-based software.

Cameron McKenzie has been a Java EE software engineer for 20 years. His current specialties include Agile development; DevOps; Spring; and container-based technologies such as Docker, Swarm and Kubernetes.

View All Videos