[java] Apache Maven install "'mvn' not recognized as an internal or external command" after setting OS environmental variables?

I've followed the official installation instructions here for Windows XP. But sometimes when I execute mvn --version, I receive the error message,

'mvn' not recognized as an internal or external command

I've even rebooted my machine a couple times, but the OS does not always recognize the maven command. But when I execute either, cd %M2_HOME%, or cd %M2% it brings me to the installation directory. I've also made sure to add the user variable M2 to the Path system variable.

So, what gives?

This question is related to java apache maven windows-xp

The answer is


running maven to win 7

  1. unzip apache-maven to directory C:\Program Files\apache-maven-3.2.1
  2. go to [Enviroment Variables] set [path] C:\Program Files\apache-maven-3.2.1\bin;
  3. open cmd and type C:\Program Files\apache-maven-3.2.1> mvn -version

You need to set M2 and M2_HOME. I was facing same problem and issue was I had put one extra space in PATH variable after semicolon. Just removed space from path and it worked. (Windows 7 machine)


Running command prompt as Administrator solved the problem for me. I did not have to move M2 or M2_HOME under system variables.


I had this same problem, restart the command prompt and then check try mvn --version. It was probably set and working the whole time but command prompt needed to be restarted to be able to access the new system variable.


I have got it solved by adding Path variable in user variables as %JAVA_HOME%\bin;%M2_HOME%\bin;


Installtion Steps

  1. Download Binary zip archive or tar.gz.
  2. Copy in the respective folder. Example - C:\apache-maven-3.3.9
  3. Add Variable (either user or system) M2_HOME = C:\apache-maven-3.3.9
  4. Add Variable (either user or system) MAVEN_HOME = C:\apache-maven-3.3.9
  5. Update Variable PATH with C:\apache-maven-3.3.9\bin
  6. Open CMD and Type mvn -v or mvn --version it should give the below response

C:\Users\XXXXXXX>mvn --version Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T22:11:4 7+05:30) Maven home: C:\apache-maven-3.3.9 Java version: 1.8.0_40, vendor: Oracle Corporation Java home: C:\Program Files\Java\jdk1.8.0_40\jre Default locale: en_US, platform encoding: Cp1252 OS name: "windows 8", version: "6.2", arch: "amd64", family: "dos"

**Make sure all variables have correct values using echo %M2_HOME% on CMD


I've suffered from this problem and found that, for some reason or other, environment variables were simply not being parsed (executing cd %M2% told me that there was no folder %M2% in the current directory). In the end adding the explicit path to Maven's executable worked for me:

C:\apache-maven-3.1.0\bin


Delete M2 and M2_HOME from user variables and move to system variables. That will solve the problem


As others have done, creating new System variables M2 and M2_HOME solved the problem. Just making User variables M2 and M2_HOME on my Windows XP machine led to maven not being recognised from the command line. I then deleted the User variables, created copies as System variables and it all came to life.

This was apache-maven-3.0.4 with XP sp3. So the instructions in: http://maven.apache.org/download.cgi seem incorrect.


Looks like maven is not present in your PATH. Add the absolute maven home\bin location to your PATH.


same problem.

and I solved it by:

  1. add C:\Program Files\apache-maven-3.3.9\bin; to PATH
  2. run cmd as administrator

and then mvn --version works.


Maven should be configured in the following way (can be user variables or system): - M2: %M2_HOME%\bin - M2_HOME: (your directory to Maven's root, not \bin) - PATH: %PATH%;%M2%

You should then be able to run mvn from the command prompt.


Assuming you've created the variable path for maven as follows:

Under System path, click new then edit as follows:

Variable name: MAVEN_HOME

Variable value: C:\Program Files\apache-maven-3.5.3\bin

Then continue with these instructions:

Under System Path, update variable path by clicking on edit and add:

C:\Program Files\apache-maven-3.5.3\bin;

immediately after:

C:\Program Files\Java\jdk\1.8.0_161\bin;

remember to add semi-colon ; after \bin as included above and then run your cmd prompt and type:

mvn -v 

I solved this by creating all under user variables (including the PATH variable). This is because the system variables do not "translate" the user variables. So if you only want to use maven in your account, you need to add another PATH variable as a user variable, not system variable.


Most probably you may have not installed maven correctly. use this to download maven. Download the latest (Binary tar.gz) file.It worked for me.


I was facing the same issue and then I closed and reopened cmd.exe to get mvn -vto propagate to my command prompt.

If cmd was open when you set the variables they will not be available in that session.


Heres what i did wrong:

1) make sure its NOT in a [C:\Program Files (x86)] it should be in [C:\Program Files] i am not 100% if that could break it but you never know.

2) There were 3 things i needed to do in my Environment Variables to get it to work

  1. Create a user var like this [ M2 = %M2_HOME% ]
  2. Create a user var like this [M2_HOME = C:\Program Files\Apache Software Foundation\apache-maven-3.2.2]
  3. Edit the PATH to [What ever is already in here +];%M2%

Just adding some more info that solved the problem for me:

  • Make sure that the %M2% and %M2_HOME% variables doesn't have the semicolon (;) at the end. This should only be used if there are more than one location in that path, which is not the case;
  • Also, make sure that in the "Path" variable, there aren't any spaces between the various paths, separated by the semicolon.

Thanks to Pawan Valecha and Abhijeet Sawant for the tips.


  1. Download apache-maven-3.3.9-bin.zip file and extract it.

  2. Then set system variable M2_HOME = B:\sql software\apache-maven-3.3.9 or as appropriate

  3. Also set variable M2 = %M2_HOME%\bin

  4. Open CMD and write mvn

I solved thank you


Make sure that you haven't renamed some folder which falls in the path of the M2 environment variable. In case you have, then change your M2 and/or M2_HOME accordingly.

It doesn't matter whether M2 or M2_HOME are System Variable or User Variables as long as you are logged in with the same user under whose scope the environment variables are.


Add your Maven bin path to the System variable as given below

Go to the

> Enviornment Variables > set Path=D:\apache-maven-3.2.1\bin

or if path is already set than append the path with ";"

restart command and try


I had similar issue on Windows 7. At first I setup M2, M2_HOME under User variable but when I echoed %PATH% , I did not see maven bin directory listed under PATH. Then I setup M2, M2_HOME under system variable and it worked.


Had the same problem,

mvn --version

worked but

maven --version

did not. I prefer using 'mvn' over 'maven' anyway so all is well. I also logout/login in to be sure.


The accepted answer didn't help but simple step below fix it !

Under system PATH: instead of using M2%, use %M2_HOME%\bin, as simple as that.

N.B my %M2_HOME% is pointing to %MV3_HOME% instead of actual absolute path bcos I have multiple version of maven installed and trying to be clever (switch between maven versions on the same box for different project).


I was facing the same issue while executing the command mvn -version; however, I checked I had also set the mvn options in the environment variables setting, which gave me some Heap memory issue on the command prompt. So, I removed the maven options that I had set and then it worked fine for me.


I had the same issue, there was no issue in my syntax, but when I moved the M2, M2_HOME, JAVA_HOME environment variables from user to system it started working. Path variables stayed the same.


A temporary work around would be to set the path from the terminal itself. Worked for me after that. Running as administrator also works. Both M2 and M2_HOME are already set as system variables in my case.


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to apache

Enable PHP Apache2 Switch php versions on commandline ubuntu 16.04 Laravel: PDOException: could not find driver How to deploy a React App on Apache web server Apache POI error loading XSSFWorkbook class How to enable directory listing in apache web server Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details How to enable php7 module in apache? java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient The program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing while starting Apache server on my computer

Examples related to maven

Maven dependencies are failing with a 501 error Why am I getting Unknown error in line 1 of pom.xml? Why am I getting "Received fatal alert: protocol_version" or "peer not authenticated" from Maven Central? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Unable to compile simple Java 10 / Java 11 project with Maven ERROR Source option 1.5 is no longer supported. Use 1.6 or later 'react-scripts' is not recognized as an internal or external command How to create a Java / Maven project that works in Visual Studio Code? "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository Java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException

Examples related to windows-xp

installing JDK8 on Windows XP - advapi32.dll error How to Create a script via batch file that will uninstall a program if it was installed on windows 7 64-bit or 32-bit How do I find files with a path length greater than 260 characters in Windows? Apache Maven install "'mvn' not recognized as an internal or external command" after setting OS environmental variables? How to access share folder in virtualbox. Host Win7, Guest Fedora 16? How to create ls in windows command prompt? How to fix an UnsatisfiedLinkError (Can't find dependent libraries) in a JNI project How to use random in BATCH script? How to delete or change directory of a cloned git repository on a local computer How do I manually create a file with a . (dot) prefix in Windows? For example, .htaccess