<img alt="JAVA_HOME Path" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/ubuntu-java-home-path.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="512" src="data:image/svg xml,” width=”1024″>
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.
<img alt="Install OpenJDK on Ubuntu Linux" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/ubuntu-install-openjdk2-1024×550.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="403" loading="lazy" src="data:image/svg xml,” width=”750″>
Once you’ve entered that, wait for the system to finish the installation and then move on to step 2.
Set JAVA_HOME Path
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/
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
<img alt="Ubuntu JAVA_HOME Path" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/ubuntu-java-home-path.png62625e90e2996.jpg" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="250" loading="lazy" src="data:image/svg xml,” width=”762″>
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.Advertisement
This will append the java bin directory to the existing PATH variable. You can also check the PATH variable by entering the following command
<img alt="Ubuntu Java Binary Path" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/ubuntu_java_bin_path-1024×203.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="149" loading="lazy" src="data:image/svg xml,” width=”750″>
Test JAVA setup
You have successfully installed OpenJDK on your machine. You can verify your installation by entering the following command on your terminal.
<img alt="Check Java version" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/check-java-version.jpg" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="204" loading="lazy" src="data:image/svg xml,” width=”767″>
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.