[java] 'mvn' is not recognized as an internal or external command, operable program or batch file

May be question is asked before but i found very strange kind of error. When I run mvn --version command from bin its gives the version and the other information. However when I run outside bin it gives exception. Both the result mention below

C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5\bin>mvn --version
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 19:21:
28+0530)
Maven home: C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_25\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5>mvn --version
'mvn' is not recognized as an internal or external command,
operable program or batch file.

Also i set JAVA_HOME in user variable and M2_HOME, M2 in system environment variable output is

C:\Users\SAHILBHALLA>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.7.0_25

C:\Users\SAHILBHALLA>echo %M2%
C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5\bin

C:\Users\SAHILBHALLA>echo %M2_HOME%
C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5

Tell me where i am wrong. What should i do recover from it?

This question is related to java maven-2 maven-3

The answer is


My problem solved, path didn't resolve %M2%. When i added location of maven-bin in the path instead of %M2% after that commands works.

I would like to thanks to all those who try to solve the problem


maven should be on the system's PATH if you wish to execute it from any place. add %M2_HOME%\bin to the PATH


This problem arise because there is no any environmental variable corresponding to installed maven in your OS. For fixing this problem, I always use Intellij's bundled Maven and do not install separate version of Maven again, for finding bundled Maven's path go to intellij and hit Ctrl+Alt+S -> Build, Execution, Deployment -> Build tool -> Maven -> Maven home directory you can find the intellij's bundled maven path there as below image demonstrates.

enter image description here

Then go to System environment variables and set these variables:

Variable name: MAVEN_HOME

Variable value: C:/Program Files/JetBrains/IntelliJ IDEA 2019.3.1/plugins/maven/lib/maven3

enter image description here

After defining system variable MAVEN_HOME find variable path and add this line to the list

%MAVEN_HOME%\bin

enter image description here

Work is done, open command prompt and test it by writing mvn -v. 99 percent of the time it work, if you're among 1 percent, you have to restart your computer.

If you want to use mvn command from intellij's internal terminal you have to restart intellij after setting environment variables, then you shouldn't have any problem running maven command from terminal.


Here is the best Maven-Environment Setup tutorial for Windows, Unix and Mac Operating systems.

But in the last you have to set value of PATH variable as ";%M2_HOME%\bin" instead of "%M2%", because PATH variable is not able to reduce the value using "%M2%"


After setting the path with the Maven bin location close the prompt window and restart it. Use the echo %path% command to make sure the path is set with Maven variables then run the command mvn -version. Somehow if the path is set when the prompt window is running it does not pick the new variables.


First of all make sure you java is working or not run this command in cmd

 C:\>java -version

if it's working it will show this output:-

C:\>java -version
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) Client VM (build 25.74-b02, mixed mode)

step 1. First set your java_home[C:\Program Files\Java\jdk1.8.0_74] path in user variable.

step 2. Then set MAVEN_HOME[C:\Program Files\maven\apache-maven-3.3.9] path in system variable and make sure your maven folder should be present in C folder only.

step 3. Then set M2 path in system variable and give maven bin location there i.e.[C:\Program Files\maven\apache-maven-3.3.9\bin].

Step 4. Then set new system variable i.e. variable name = MAVEN_OPTS in and variable value =-Xms256m -Xmx512m

Step 5. Then edit path/system path variable be care full don't remove anything from there simply add java_home path i.e=;C:\Program Files\Java\jdk1.8.0_74 and M2 variable=;%M2% in the end.

Step 6. To make sure maven is now working or not run this command in cmd

> C:\>mvn --version

if it's working it will show this result :-

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-
7+05:30)
Maven home: C:\Program Files\maven\apache-maven-3.3.9\bin\..
Java version: 1.8.0_74, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_74\jre
Default locale: en_IN, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "dos"

In windows 7, I Got it resolved after adding the environment variables in system level. If you do not have enough permission try to set the %JAVA_HOME% and the %M2_HOME% in System variables instead of User Variables.


The following helped me in Win10.

  • Add %M3_HOME%\bin; as value for Path variable under User Variables.
  • Add full path to maven binary folder as Variable Value for M3_HOME variable under System Variables.
  • Add %M3_HOME%\bin; as value for Path variable under System Variables.
  • Click OK wherever applicable.
  • Close the existing command prompt.
  • Open new command prompt and navigate to Maven binary folder.
  • Type mvn -version

It will work.


I prefer adding path to ~/.bashrc.

vim ~/.bashrc, then add these lines:

export M2_HOME=/usr/local/apache-maven-your_maven_path&version
export M2=$M2_HOME/bin

Go to Environment Variable and paste the following:

Under System Variable: Step 1: New --> New User Variable 1. Variable name: MAVEN_HOME 2. Variable_value : D:\apache-maven-3.5.2

Step 2: 1. Go to the path --> and paste this - %MAVEN_HOME%\bin


To solve this problem please follow the steps below:

  1. Download the maven zip file from http://maven.apache.org/download.cgi
  2. Extract the maven zip file
  3. Open the environment variable and in user variable section click on new button and make a variable called MAVEN_HOME and assign it the value of bin path of extracted maven zip
  4. Now in System Variable click on Path and click on Edit button --> Now Click on New button and paste the bin path of maven zip
  5. Now click on OK button
  6. Open CMD and type mvn -version
  7. Installed Maven version will be displayed and your setup is completed

Go to the shell (cmd for windows) and set the path variable manually from there. It works often from there. Read more at http://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/


In Windows 10, I had to run the windows command prompt (cmd) as administrator. Doing that solved this problem for me.


got it solved by first creating new "Path" variable under User variables (note that after fresh windows install Path variable is not created as User variable, only as system) after that, I appended %M2% (pointing to maven dir/bin) to (freshly created) user Path variable. after that restarted cmd window and it worked like a charm.


I did all of this in Windows 10 and still had a problem. In the end it turned out that the path to the Maven home folder was not exactly what was expected in many of these answers as it turned out to be /apache-maven-3.6.3-bin/apache-maven-3.6.3. Once I corrected this for both the system variables and the PATH variable, it worked. In short, if you have set the environment variables up as directed and it still won't work, I would double check to make sure the variables really point to the exact path to the Maven home folder and the bin folder on your machine.


Place the full path to mvn in your PATH environment variable.


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 maven-2

Maven:Non-resolvable parent POM and 'parent.relativePath' points at wrong local POM Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project. Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved Maven Error: Could not find or load main class MAVEN_HOME, MVN_HOME or M2_HOME Where is my m2 folder on Mac OS X Mavericks Maven won't run my Project : Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec 'mvn' is not recognized as an internal or external command, operable program or batch file SLF4J: Class path contains multiple SLF4J bindings Create local maven repository

Examples related to maven-3

Failed to read artifact descriptor for org.apache.maven.plugins:maven-source-plugin:jar:2.4 Specifying java version in maven - differences between properties and compiler plugin m2e error in MavenArchiver.getManifest() How do I force Maven to use my local repository rather than going out to remote repos to retrieve artifacts? Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved MAVEN_HOME, MVN_HOME or M2_HOME Cannot load properties file from resources directory 'mvn' is not recognized as an internal or external command, operable program or batch file 'dependencies.dependency.version' is missing error, but version is managed in parent Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile)