The JAVA_HOME environment variable is not defined correctly, but it is defined correctly! Ubuntu 18.04.01

Viewed 3708

I am trying to run maven on Ubuntu. Every time I run something like mvn -v I get: "The JAVA_HOME environment variable is not defined correctly This environment variable is needed to run this program NB: JAVA_HOME should point to a JDK not a JRE".

The thing is that I have set JAVA_HOME correctly. In /etc/environment: JAVA_HOME="/usr/lib/jvm/java-8-oracle".

Also, if I try echo $JAVA_HOMEit returns "/usr/lib/jvm/java-8-oracle", which is correct.

Am I doing something wrong?

1 Answers

Most probably ubuntu source /etc/environment is set by default. If it does not work you need to add the below line inside ~/.bashrc

open it using nano/vim or any editor with sudo perimissions. Then add below line

source /etc/environment
Related