Many Java-based programs require the Java Runtime Environment (JRE) to run smoothly regardless of the operating system. For development, most IDEs like Eclipse and NetBeans require the Java Development Kit (JDK) on your computer. Whether you’re a newbie who wants to learn how to develop or an application you have installed requires a Java installation on your system, we’ve got you covered. Setting up the JAVA_HOME path is quite simple.

In this tutorial, we will learn how to install the JDK on Ubuntu 20.04 and Ubuntu 22.04 and set up the Java_HOME path. Let’s start with the installation of the JDK.

Install OpenJDK on Ubuntu

Note: Make sure that you have updated the Advanced Package Tool (APT) before you move forward to install OpenJDK.

Press Ctrl + Alt + T to open the terminal and enter the following command mentioned in the box. You can either install OpenJDK 8 or the newer versions OpenJDK 11 to OpenJDK 18. Not all versions are available on any Ubuntu version, you can check for available versions with the command:

apt-cache search openjdk-

Install OpenJDK 8

sudo apt install openjdk-8-jdk

Install OpenJDK 11

sudo apt install openjdk-11-jdk

Install OpenJDK 14

sudo apt install openjdk-14-jdk

Install OpenJDK 16

sudo apt install openjdk-16-jdk

Install OpenJDK 17

sudo apt install openjdk-17-jdk

Install OpenJDK 18

sudo apt install openjdk-18-jdk

You will be prompted to enter your sudo password to continue with the installation.

Install OpenJDK on Ubuntu Linux

Once you’ve entered that, wait for the system to finish the installation and then move on to step 2.


All you have to do now is to set the “JAVA_HOME” and “PATH” environment variables and then you are done. Enter the following commands to set your environment variables. Make sure that your environment variables point to a valid installation of JDK on your machine. For Ubuntu 18.04, the path is /usr/lib/jvm/java-8-openjdk-amd64/

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

To check whether your JAVA_HOME path has been successfully saved, enter the following command to check.


The value stored in the JAVA_HOME variable will be displayed on the terminal as you can see in the screenshot

Ubuntu JAVA_HOME Path

Add JAVA bin directory to the PATH variable

Like we have added JAVA_HOME path, we will now update the PATH variable as well. To do that, enter the following command on the terminal.

export PATH=$PATH:$JAVA_HOME/bin

This will append the java bin directory to the existing PATH variable. You can also check the PATH variable by entering the following command

echo $PATH

Ubuntu Java Binary Path

Test JAVA setup

You have successfully installed OpenJDK on your machine. You can verify your installation by entering the following command on your terminal.

java -version

Check Java version

Through this simple tutorial, you have now configured the JAVA_HOME variable in your operating system. You can now easily run java based applications as well as development environments on your machine.

How to Set JAVA_HOME Path in Ubuntu 20.04 and Ubuntu 22.04

Leave a Reply

Your email address will not be published. Required fields are marked *