Biplov Shrestha
Biplov Shrestha

Reputation: 11

Error: JAVA_HOME is not defined correctly

echo $JAVA_HOME

gives: /usr/lib/jvm/java-6-sun but I've set /usr/lib/jvm/java-7-openjdk-amd64 in /etc/environment

source /etc/environment

gives the path I've set i.e /usr/lib/jvm/java-7-openjdk-amd64

The next time I try echo $JAVA_HOME, the wrong path is displayed.

Upvotes: 0

Views: 584

Answers (2)

taisph
taisph

Reputation: 251

On Ubuntu the recommended way seems to be to add the line JAVA_HOME=/usr/lib/jvm/default-java to /etc/environment and use the update-alternatives tool to manage the actual jvm.

You may have a script in /etc/profile.d/ overriding this which should be removed.

You can see which java alternatives are currently installed and available by running:

update-java-alternatives --list

To choose a jvm to use, run the following command with whatever version suits you:

update-java-alternatives --set java-1.7.0-openjdk-amd64

Upvotes: 1

Aaron Digulla
Aaron Digulla

Reputation: 328546

There is probably code in /etc/profile or ~/.bashrc which sets the variable again.

Try grep -r JAVA_HOME /etc and grep JAVA_HOME ~/.??* to find places where it's used.

To avoid trouble like this, I usually create shell scripts in ~/bin/ which have the same name as the tool that I want to execute which prepare the environment.

Upvotes: 1

Related Questions