0

I try to set JAVA_HOME variable on an ubuntu server. I get the Java path with this command which java

/usr/bin/java

I set the result in /etc/environment

JAVA_HOME="/usr/bin/java"

When I try to run a mvn command I get this error

Error: JAVA_HOME is not defined correctly.
  We cannot execute /usr/bin/java/bin/java
user3235881
  • 487
  • 2
  • 9
  • 24
  • ``JAVA_HOME`` is not supposed to point to the executable binary but to the java installation directory. – f1sh Jul 08 '16 at 12:33
  • Are you sure that adding this address "/usr/bin/java/bin" to PATH also? – ROOT Jul 08 '16 at 12:34

2 Answers2

2

You should not set JAVA_HOME to /usr/bin/java, because that's just a symbolic link to the java executable, which points to where the real executable is.

JAVA_HOME should point to the Java installation directory, and not to the java executable (or a link to the executable).

Find out where your Java installation directory is and then set JAVA_HOME to that directory (and not to the java executable). If you installed Java using Ubuntu's package management system, then the Java home directory is probably one of the subdirectories in /usr/lib/jvm.

Jesper
  • 202,709
  • 46
  • 318
  • 350
1

Per the Oracle site:

export JAVA_HOME=jdk-install-location
export PATH=$JAVA_HOME/bin:$PATH

You can add these lines into your ~/.bash_profile (or ~/.bashrc), and then refresh using source ~/.bash_profile

TayTay
  • 6,882
  • 4
  • 44
  • 65