Setting the JAVA_HOME Environment Variable in Ubuntu

Karthikeyan Thiyagarajan
1 min readSep 5, 2019

--

Many programs, such as Java servers, use the JAVA_HOME environment variable to determine the Java installation in the system. To set this environment variable, we will first need to find out where Java is installed. You can do this by executing the same command as in the previous section:

sudo update-alternatives --config java

It will returns the path where Java is installed(It returns multiple paths, when multiple Java versions are installed).

Copy the path from your preferred installation and then open /etc/environment using nano or your favorite text editor.

sudo nano /etc/environment

At the end of this file, add the following line, making sure to replace the highlighted path with your own java path.

JAVA_HOME="{/usr/lib/jvm/java-8-oracle}"

Save and exit the file, and reload the /etc/environment.

source /etc/environment

You can now test whether the environment variable has been set or not by using the command:

echo $JAVA_HOME

This will return the path you just set.

--

--

Responses (1)