I've installed a version of Java. How can we set the
$JAVA_HOME environment variable correctly?
You can set your
/etc/profile as Petronilla Escarabajo suggests. But the preferred location for
JAVA_HOME or any system variable is
/etc/environment in any text editor like
gedit and add the following line:
(java path could be different)
source to load the variables, by running this command:
Then check the variable, by running this command:
Usually most linux systems source /etc/environment by default. If your system doesn't do that add the following line to
~/.bashrc (Thanks @pje)
JAVA_HOME environment variable, do the following:
- Launch Terminal by pressing Ctrl+Alt+T on your keyboard.
- Enter the following command:
gksudo gedit /etc/environment
- Depending on where you installed your Java, you will need to provide the full path. For this example, I installed Oracle JDK 7 in the
Scroll to the end of the file and enter the following:
- Save your file and exit gedit.
- Lastly, reload the system PATH with the following command:
The above method will save you the hassle in having to run the commands every time you log in to your computer.
If you do not know the path and you only have openJDK installed, you can type
update-alternatives --config java and you should find the path. To set the variable you can write
JAVA_HOME=<PATH> followed by
export JAVA_HOME. Notice there's no space when declaring the variable. To check if the variable is stored you simply type
echo $JAVA_HOME to verify.
protected by Community♦ Mar 8 '15 at 7:48
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?