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
asked Jul 8, 2016 at 12:30
2
  • JAVA_HOME is not supposed to point to the executable binary but to the java installation directory. Commented Jul 8, 2016 at 12:33
  • Are you sure that adding this address "/usr/bin/java/bin" to PATH also? Commented Jul 8, 2016 at 12:34

2 Answers 2

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.

answered Jul 8, 2016 at 12:33

Comments

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

answered Jul 8, 2016 at 12:34

2 Comments

This is incorrect; /usr/bin/java is not the Java installation directory on Ubuntu.
@Jesper Yeah, I fixed it.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.