Last Updated on 11 months by Sachin G

Java, a powerful and versatile programming language, remains a cornerstone in various software development projects, server-side applications, and enterprise solutions. To harness the latest features, enhancements, and security updates, installing the latest Java OpenJDK version on your Ubuntu or Linux Mint system is crucial. This post shows steps on how to accomplish this task using the apt command or Debian package downloading ensuring you have access to the most recent Java release effortlessly.

If you aim to install on RPM-based operating systems such as CentOS, AlmaLinux, or Oracle Linux, you can refer to our other article. Click Here to view.

Step-by-Step Guide to Installing OpenJDK (Java Development Kit) via apt

The apt package manager simplifies the process of installing and managing software packages on Ubuntu and Linux Mint systems. Follow these steps to install the latest Java version using the apt command.

By default, the OpenJDK package is available in Ubuntu repositories, and you can check its availability as demonstrated.

 sudo apt-cache search openjdk 

After filter, which openjdk version do you want to install then you can proceed to install the latest version of Java on your system using the following command:

sudo apt install openjdk-21-jdk -y 

Replace 21 with the desired version number if a newer version is available. This command installs the, which is a popular choice for Java development.

Verify the Installation

After the installation is complete, verify that the latest version of Java has been successfully installed on your system by checking the installed Java version:

java -version 

OUTPUT

openjdk 21.0.1 2023-10-17
OpenJDK Runtime Environment (build 21.0.1+12-Ubuntu-222.04)
OpenJDK 64-Bit Server VM (build 21.0.1+12-Ubuntu-222.04, mixed mode, sharing)

You should see the above output similar to the following, indicating the installed Java version

Step-by-Step Guide to Installing Oracle Java JDK via .deb Package

Follow these steps to install Oracle Java JDK 21 on your Ubuntu or Debian-based system using the .deb package method:

Download OpenJDK 21 Oracle .deb Package

Visit the Oracle Java downloads page and Download OpenJDK 21 or which version you would like to install .deb package for your system architecture. Ensure that you download the appropriate package compatible with your system configuration.

Navigate to the Download Directory

Once the download is complete, navigate to the directory where the JDK 21 .deb package is saved. You can typically find it in the “Downloads” directory unless you specify a different location during the download.

cd ~/Downloads 

Install the Oracle JDK 17 .deb Package

Use the dpkg package manager to install the Oracle JDK 17 .deb package. Replace jdk-17.deb with the actual filename of the downloaded package.

sudo dpkg -i jdk-17_linux-x64_bin.deb 

This command installs the Oracle JDK 17 package on your system. If any dependencies are missing, dpkg will notify you, and you can resolve them using the apt package manager.

Verify the Installation

After installation, verify that Oracle JDK 17 has been successfully installed on your system by checking the installed Java version:

java -version 

You should see output similar to the following, indicating the installed Oracle JDK version:

java 17.0.10 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 17.0.10+11-LTS-240)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.10+11-LTS-240, mixed mode, sharing) 

Configure Oracle JDK as the Default Java Version (Optional)

You can have more than one Java installed on your system without big problems. But sometimes you might need to pick one as the main Java, depending on what your projects need. You can do this using the “update-alternatives” command. It helps you see the options and choose which Java you want to use by default.

sudo update-alternatives --config java 

After setting the Java version, check the Javac and jar versions respectively via the below command.

javac --version 
jar --version 

javac and jar versions will remain the same. You can switch both versions through the below command. Take guidance from the screenshot.

sudo update-alternatives --config javac 
sudo update-alternatives --config jar 

Installing Oracle Java JDK on Ubuntu or Debian-based systems using the apt method or .deb package download method empowers you with the latest tools and features for Java development.