JAVA_HOME incorrectly set. How to reset it?

user113454 picture user113454 · Mar 10, 2012 · Viewed 65k times · Source

When I try to run mvn (Apache Maven, that is), I keep getting error "JAVA_HOME" not set.

I follow the instructions to set the JAVA_HOME variable as follow; In the terminal:

user@localhost$export JAVA_HOME=/home/user/jdk1.7.0_02/bin/java

user@localhost$export PATH=$PATH:/home/usr/jdk1.7.0_02/bin

That looks correct, right? Then how come I still getting the incorrect JAVA_HOME error?

Answer

gavi picture gavi · Mar 10, 2012

JAVA_HOME typically should only include the folder that contains the bin folder.

So in your case

export JAVA_HOME=/home/user/jdk1.7.0_02/

export PATH=$PATH:$JAVA_HOME/bin

In addition for finding the location of your java_home you can follow this command

which java

(This will return the path of the current java binary. Over here its /usr/bin/java)

ls -alh /usr/bin/java

( This will return true path to the symbolic link. Over here its /etc/alternatives/java.

ls -alh /etc/alternatives/java

( This will return true path to this symbolic link which is actual JAVA HOME path)