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 LTS and then set up the java home path. Let’s start with installing 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.
sudo apt install openjdk-8-jdk
You will be prompted to enter your sudo password to continue with the installation.
Once you’ve entered that, wait for the system to finish the installation and then move onto 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
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.
This will append the java bin directory to the existing PATH variable. You can also check the PATH variable by entering the following command
Test JAVA setup
You have successfully installed OpenJDK on your machine. You can verify your installation by entering the following command on your terminal.
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.