A large number of Java-based programs require Java Runtime Environment (JRE) to run smoothly regardless of operating systems. For development purposes, most IDEs like Eclipse and NetBeans require Java Development Kit (JDK) installed on the machine. Whether you are a newbie developer looking forward to learning development or perhaps an application you have installed requires you to have Java installed on your system, we have you covered. Setting up of JAVA_HOME path is quite easy.

In this tutorial, we are going to learn how to install JDK on Ubuntu 18.04 and 20.04 and then set up the java home path. Let’s start by installing the JDK first.

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 or OpenJDK 14:

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

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 onto 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. Let us know in comments if you faced any issues while implementing this tutorial.

How to Set JAVA_HOME Path in Ubuntu 18.04 and 20.04 LTS

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn