Reputation: 497
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
Upvotes: 0
Views: 1421
Reputation: 206946
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
.
Upvotes: 2
Reputation: 7170
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
Upvotes: 1