Q:

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. 

A:

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.

