Maven 3.5 doesn't find $JAVA_HOME despite the env variable was set

maven environment variables
how to install maven
maven download
maven java
how to install maven on mac
maven -u option
maven tutorial
maven 3.5 4 release date

I am trying to run Maven 3.5 on my Ubuntu 16.04 desktop VM. I installed JDK 8 and set $JAVA_HOME and added the path. Despite this, Maven cannot find it. Here is the output:

root@ubuntu:/# echo $JAVA_HOME
opt/jdk1.8.0_131/bin/java

root@ubuntu:/# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:opt/jdk1.8.0_131/bin:opt/apache-maven-3.5.0/bin

root@ubuntu:/# mvn -v
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

Any ideas?

JAVA_HOME should point to the JDK/JRE installation directory rather than to the java executable. In your case, that seems to be /opt/jdk1.8.0_131/ (the leading / is important, in its absence every software will try to access an opt directory in its current working directory)

Then you can append $JAVA_HOME/bin to the PATH, which has correctly been done in your case but apparently does not matter to Maven.

Maven – Download Apache Maven, MNG-6190 maven-resolver-provider's DefaultArtifactDescriptorReader has mismatched constructor and initService methods (this issue does not affect normal  Maven 3.5.2 is available for download. Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central place. The core release is independent of the plugins available.

Set you path for $JAVA_HOME is

/opt/jdk1.8.0_131/         

Absolutely Correct path, it is the home directory for java. Here 1.8.0.131 is a version release to Identify the version of Java Installed.

instead of

opt/jdk1.8.0_131/bin/java   //wrong path, it is not a home directory for java

Note :- You may also install or put the extracted version for multiple versions of java.Version actually helps you to identify and choose right version according to need (if Needed).

Maven – Release Notes – Maven 3.5.0-beta-1, Maven 3.5.3 is available for download. reset when interrupting build process; MNG-6255 - Maven script cannot parse jvm.config with CRLF  Release Notes – Maven 3.5.4. The Apache Maven team would like to announce the release of Maven 3.5.4. Maven 3.5.4 is available for download. Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central place.

It is likely that your maven is in a protected directory

Run using sudo mvn -v

Maven – Release Notes – Maven 3.5.3, The installation of Apache Maven is a simple process of extracting the archive and adding the `bin` folder with the `mvn` command to the `PATH`. Detailed steps​  JAVA_HOME should point to the JDK/JRE installation directory rather than to the java executable. In your case, that seems to be /opt/jdk1.8.0_131/ (the leading / is important, in its absence every software will try to access an opt directory in its current working directory)

Maven – Installing Apache Maven, Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a  The Apache Maven team would like to announce the release of Apache Maven 3.0.5. Apache Maven 3.0.5 is available for download. Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central place.

Maven – Welcome to Apache Maven, The most important changes in Maven 3.5.0 are the following: [MNG-5823] – mvnDebug doesn't work with M2_HOME with spaces – missing  The ZTE Maven 3 features a 5-inch IPS display, 1.1GHz processor with 1 GB of RAM and 8GB storage (expandable via microSD). There is a 5-megapixel autofocus camera on the back and a 2-megapixel front shooter. The phone runs Android 7.0.

Apache Maven 3.5.0 is here: Nothing to see in 3.4.0, move along , Verify the installation by running the mvn -version command: mvn -version. The output should look something like this: Apache Maven 3.5.2  Maven Cucumber Reporting 4 usages net.masterthought » maven-cucumber-reporting » 5.3.0 LGPL This project provides a maven mojo for using cucumber-reporting to publish pretty html reports for Cucumber.