Monday, June 5, 2017

How to set JAVA_HOME in linux?

Open /etc/environment in any text editor like nano or gedit and add the following line:

JAVA_HOME="/usr/lib/jvm/open-jdk"
(java path could be different)

Use source to load the variables, by running this command:

source /etc/environment
Then check the variable, by running this command:

echo $JAVA_HOME
Update

Usually most linux systems source /etc/environment by default. If your system doesn't do that add the following line to ~/.bashrc (Thanks @pje)

source /etc/environment

Resource Link: https://askubuntu.com/questions/175514/how-to-set-java-home-for-java

Another Section:

1. sudo update-alternatives --config java

2. sudo gedit /etc/environment
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
JAVA_HOME="/usr/lib/jvm/java-7-oracle"
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"

3. source /etc/environment

No comments:

Post a Comment