Maven M2_HOME set to an invalid directory (Windows 7)

匿名 (未验证) 提交于 2019-12-03 01:54:01


I've tried installing Maven to Windows 7 with poor results. Some basic info:

Maven installation directory: C:\Program Files\Apache Software Foundation\apache-maven-3.0.4 System Variable "M2_HOME": C:\Program Files\Apache Software Foundation\apache-maven-3.0.4\ System Variable "Path" : %M2_HOME%apache-maven\src\bin;%JAVA_HOME%\bin

If I run mvn --version in the command path, I get the error message:

Please set the M2_HOME variable in your environment to match the location of the Maven installation

So at the moment the subdirectory for mvn is not set according to the instructions, which would be %M2_HOME%\bin. If I replace %M2_HOME%apache-maven\src\bin with that one, I get:

mvn is not recognized as an internal or external command, operable program or batch file

In the Maven installation directory (or in the zip-file) there is no \bin folder directly in apache-maven-3.0.4 and I wonder if there should be one?

I'm a complete novice to Maven, hopefully you guys can help.

By the way the Java command works from any directory, so I don't think that's the issue here, but I can't be sure.


If your downloaded package apache-maven-3.3.9 does not contain a bin folder your download is wrong. you have to download a zip file which contains bin, boot, conf, lib folder otherwise there has gone something wrong. The downloaded file should have about 4.8 mb size. You can check the file via md5 or SHA1 checksums.


In M2_HOME - set C:\apache-maven-3.0.4 i.e. path without bin. In PATH - set %M2_HOME%\bin i.e. with bin in path.


In 3.3.1 *.bat files disappeared and just *.cmd files remained. .CMDs are the same as .BAT and some software expects them. I have renamed .CMDs to .BATs in order make it running under Netbeans. It caused "Maven M2_HOME set to an invalid directory". Copying .BATs to .CMDs (i.e. both were in the folder) solved the problem.


In my case the setup was correct:

Windows System Variables:

  • M2 C:\dev\software\apache-maven-3.3.9\bin
  • M2_HOME C:\dev\software\apache-maven-3.3.9

Windows User variables:

  • %M2_HOME%\bin

But I had the same problem when there was two installation of maven even though all references was pointing to the latest version which in my case was 3.3.9. After deleting the older version the same command recognised maven.


maven -v ERROR: M2_HOME is set to an invalid directory. M2_HOME = "C:\dev\software\apache-maven-3.3.9" Please set the M2_HOME variable in your environment to match the location of the Maven installation


maven -v Apache Maven 3.3.9 Maven home: C:\dev\software\apache-maven-3.3.9 Java version: 1.7.0_51, vendor: Oracle Corporation Java home: C:\Program Files\Java\jdk1.7.0_51\jre


You need to download the Maven file that has the name "Binary zip". For example:


I've the same problem on my computer and I resolved it :

  • I deleted the Maven directory and the Maven environment variables
  • I downloaded the binary zip archive on
  • I unzipped it on C:\maven
  • I added new environement variable : C:\maven in M2_HOME, %M2_HOME%\lib in M2 and %M2% added in PATH

And it works !


For me, the PATH variable had old version of maven. So I updated it. I should use %M2_HOME% but I had spelled out the path.


Just now I faced the same issue. In my case the problem was that PATH wasn't set properly to include %M2_HOME%\bin. Once set properly, the problem was resolved.

When you face such issues, please print the value of PATH on the command line to ensure that it's properly picking up the values.


All success after next steps.

  1. On page from 4 variants need download binary file.

  2. Set environment variable (tip from @JamesB -

JAVA_HOME=C:\Program Files\Java\jdk1.6.0_35



  1. Run mvn -version


Had an old version of MVN in another directory that showed up in the search path. Removed the old version and everything worked. Used windows file search to scan the drive for all instances of "mvn" to find the old version.


Add entire bin location to "PATH" environment variable Ex: C:\Program Files\Apache Software Foundation\apache-maven-3.0.4\bin

No need of M2_HOME, M2.It worked for me

Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\XXXX>mvn -version Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T22:11:47+05:30) Maven home: C:\Program Files\Apache Software Foundation\apache-maven-3.3.9\bin.. Java version: 1.8.0_91, vendor: Oracle Corporation Java home: C:\Program Files\Java\jdk1.8.0_91\jre Default locale: en_US, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"


Check the System Variable M2_HOME and PATH in different maven locations.


set 'M2_HOME' and 'PATH' in environment variables for your account, remove 'PATH' from system environment variables.


Get rid of the env variable M2_HOME. It is not used by maven 3, and in fact, confuses it. If you had used it in your path, then either define the path to maven bin explictly, or change it to something else - like M3_HOME.