mvn command is not recognized as an internal or external command
Asked Answered
P

30

97

I am getting the mvn command not recognized as an internal or external command.

I have setup the M2_HOME, JAVA_HOME and added %M2_HOME%/bin to the path variable. All are system variables. Still getting the same problem.

Echoing the variables showing me the correct paths.

Path to Maven: C:\apache-maven-3.1.0\apache-maven-3.1.0

M2_HOME:C:\apache-maven-3.1.0\apache-maven-3.1.0

PATH: Other things,C:\Program Files (x86)\Java\jdk1.7.0_40\bin,C:\apache-maven-3.1.0\apache-maven-3.1.0\bin

and I have restarted my computer twice.

Poling answered 30/9, 2013 at 9:35 Comment(5)
it seems the maven installation is not done properly..Beggs
i downloaded apache-maven-3.1.0-bin.zip for windows 7 32 bit and extracted to my location . Then i have setup my variables. Do i need to anything else. If i navigate to the maven bin folder and then pressin mvn then its working finePoling
follow this tutorial for installing maven.Pappy
Make sure you download maven binary file instead of source code.Delmerdelmor
It might used to work but now it doesn't work anymore. Following these steps keep windows from failing to recognize 'mvn' command.Armes
D
42

Restart your machine, after setting up your M2_HOME (pointing to you Maven basedir, NOT the bin dir) and PATH (PATH=%M2_HOME%\bin;%PATH%).

Then do:

dir "%M2_HOME%\bin\mvn*

If there is a .bat file, it should work under Windows, as it appears to be finding it. If there isn't one, then your paths are not right and you need to make sure your %PATH% variable really points to the correct path to Maven.

Make sure you are using the proper slashes for your OS. Under Windows they're \.

Drollery answered 30/9, 2013 at 10:30 Comment(7)
thanks Carl ...i can find my bat file..mvn is still not recornized..what else can i do ?Poling
Show us your path to Maven, your M2_HOME and PATH variables and tell us if you've restarted your machine.Drollery
Path to Maven: C:\apache-maven-3.1.0\apache-maven-3.1.0 M2_HOME:C:\apache-maven-3.1.0\apache-maven-3.1.0 PATH: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;c:\Program Files (x86)\Microsoft Application Virtualization Client;c:\Program Files (x86)\Open Text\View\bin;%systemroot%\System32\WindowsPowerShell\v1.0\;C:\Program Files\ThinkPad\Bluetooth Software\;C:\Program Files\ThinkPad\Bluetooth Software\syswow64;C:\Program Files\Perforce,C:\Program Files (x86)\Java\jdk1.7.0_40\bin,C:\apache-maven-3.1.0\apache-maven-3.1.0\bin and i have restarted my computer twicePoling
Instead of a ";", you have ",". This is causing your problem. Furthermore, M2_HOME should be prepended, not appended, meaning it should be at the very start, not at the end of your PATH.Drollery
thanks a lot carlspring...dont know how the ',' came...';' solved the problemPoling
@Drollery Why have you added the suffix %PATH% in the M2 PATH (end of your answers 1st sentence) Also when I reboot my system it doesn't recognize the mvn command & then I need to reconfigure the Maven Home to point to again to the same directory My maven path is C:\maven\apache-maven-3.5.4 M2_Home = C:\maven\apache-maven-3.5.4 PATH configured as %M2_HOME%\binRudin
I've appended the %PATH% (under Windows, or $PATH under Linux/Unix), so that the rest of the PATH command is appended after the path to your M2_HOME variable. M2_HOME is case sensitive on some operating systems.Drollery
T
94

Right click on My Computer >> Properties >> Advanced system settings >> System Properties window will get displayed Under Advanced >> Environment Variables

Click on New to set Environment Variables

Variable name: JAVA_HOME Variable value: C:\Program Files\Java\jdk1.8.0_121

Variable name: M2 Variable value: %M2_HOME%\bin

Variable name: M2_HOME Variable value: C:\Program Files\Apache Software Foundation\apache-maven-3.5.0

Variable name: Path Variable value: %M2_HOME%\bin

Then click on Ok, ok, ok. Now restart you command prompt and check again with “mvn --version” to verify the mvn is running, you may restart your system also.

It should be working now.

Tambratamburlaine answered 20/7, 2017 at 3:6 Comment(5)
I would like to add that you can just add in the last step instead of %M2_HOME%\bin just M2 in Path variable valueSrini
This is not valid anymore 2022. There is no folder 'C:\Program Files\Apache Software Foundation'Uncouth
I would like to know if all these variables M2, M2_HOME are documented anywhereBevbevan
@user1034912, I guess that step should be read like "whatever path your maven is installed at". For that sort of software, I install in a place called `C:\Not Program Files` for instancePiers
It might used to work but now it doesn't work anymore. Following these steps keep windows from failing to recognize 'mvn' command.Armes
D
42

Restart your machine, after setting up your M2_HOME (pointing to you Maven basedir, NOT the bin dir) and PATH (PATH=%M2_HOME%\bin;%PATH%).

Then do:

dir "%M2_HOME%\bin\mvn*

If there is a .bat file, it should work under Windows, as it appears to be finding it. If there isn't one, then your paths are not right and you need to make sure your %PATH% variable really points to the correct path to Maven.

Make sure you are using the proper slashes for your OS. Under Windows they're \.

Drollery answered 30/9, 2013 at 10:30 Comment(7)
thanks Carl ...i can find my bat file..mvn is still not recornized..what else can i do ?Poling
Show us your path to Maven, your M2_HOME and PATH variables and tell us if you've restarted your machine.Drollery
Path to Maven: C:\apache-maven-3.1.0\apache-maven-3.1.0 M2_HOME:C:\apache-maven-3.1.0\apache-maven-3.1.0 PATH: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;c:\Program Files (x86)\Microsoft Application Virtualization Client;c:\Program Files (x86)\Open Text\View\bin;%systemroot%\System32\WindowsPowerShell\v1.0\;C:\Program Files\ThinkPad\Bluetooth Software\;C:\Program Files\ThinkPad\Bluetooth Software\syswow64;C:\Program Files\Perforce,C:\Program Files (x86)\Java\jdk1.7.0_40\bin,C:\apache-maven-3.1.0\apache-maven-3.1.0\bin and i have restarted my computer twicePoling
Instead of a ";", you have ",". This is causing your problem. Furthermore, M2_HOME should be prepended, not appended, meaning it should be at the very start, not at the end of your PATH.Drollery
thanks a lot carlspring...dont know how the ',' came...';' solved the problemPoling
@Drollery Why have you added the suffix %PATH% in the M2 PATH (end of your answers 1st sentence) Also when I reboot my system it doesn't recognize the mvn command & then I need to reconfigure the Maven Home to point to again to the same directory My maven path is C:\maven\apache-maven-3.5.4 M2_Home = C:\maven\apache-maven-3.5.4 PATH configured as %M2_HOME%\binRudin
I've appended the %PATH% (under Windows, or $PATH under Linux/Unix), so that the rest of the PATH command is appended after the path to your M2_HOME variable. M2_HOME is case sensitive on some operating systems.Drollery
T
29

Write the entire maven path into the Environment PATH variable.

Example:

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

My PATH variable wasn't reading %M2% or %M2_HOME%\bin properly, and therefore I wrote the full path into the PATH variable.

Working.

Throughcomposed answered 25/9, 2014 at 21:10 Comment(1)
This worked (Windows 11)Hopefully
U
17

This is worked for me:

1-download apache-maven-3.3.9-bin.tar.gz file from https://maven.apache.org/download.cgi

2-copy the folder under c:\programfiles

3-set variables as this: M2_HOME ----- C:\Program Files\apache-maven-3.3.9 M2 ----- C:\Program Files\apache-maven-3.3.9

add Path variable to this: ;C:\Program Files\apache-maven-3.3.9\bin

then run the cmd as system admin

it worked.

Unnamed answered 2/3, 2016 at 12:27 Comment(0)
Y
6

I also was facing with the same issue still after adding path in environment variable and running it as a normal user in command prompt.

Then I opened command prompt and tried running as "Run as Administrator" and I was able to download all the packages with respect to the project.

Yeomanly answered 1/10, 2018 at 7:10 Comment(0)
O
6

Windows 10 -

  1. Add new variable "M2_HOME" -

enter image description here

  1. Update variable "path" - enter image description here

  2. Verify on cmd - enter image description here

Oppressive answered 6/12, 2020 at 19:41 Comment(0)
S
6

If you've already set the JAVA_HOME and M2_HOME (or MAVEN_HOME in my case) environment variables and added the \bin folder to the Path environment variable and still not working, then this solution could be for you.

Make sure that you have set your variables in the right order, your %JAVA_HOME%\bin folder should be added before the %MAVEN_HOME%\bin just like the shown image

right order of env variables

wrong order of env variables

Shamanism answered 22/3, 2021 at 16:3 Comment(0)
C
4

Are you trying to reference a user variable in system variables? Try echo %path% and the M2 should have been fully expanded to show the file path to your Maven directory. If it hasn't, then that's the problem.

To fix it, you should create a user variable called PATH and add your %M2% reference into there.

Cabotage answered 12/10, 2013 at 13:17 Comment(2)
What do the parentheses in %path% mean?Rough
@Rough It means that it's a variable.Aspen
W
4

Open Command prompt As "Run As a administrator" and try.

Warfield answered 2/4, 2015 at 6:59 Comment(0)
S
3

I have a stupid comment but someone else will have that issue. I was getting that same error when I was trying to put in ./mvnw clean package and I found out that I had to change it a bit to .\mvnw clean packageand I lived happily ever after.

Suspender answered 1/6, 2020 at 13:21 Comment(0)
B
2

Try %M2_HOME%\bin (\ rather than /)

Breadfruit answered 30/9, 2013 at 9:38 Comment(1)
Also sometimes you need to restart Windows.Frailty
I
2

I faced this problem which kept me busy and buggy for quiet sometime. I was facing the problem (mvn not recognized) after setting up all required environment variables absolutely correctly. So by going by one of the response here, I switched to another version of maven and that fixed the problem.

Not being completely convinced why it worked this way, I then unzipped the problematic-version and updated env-vars which made it work.

The problem was when I initially extracted file from the zip, I modified the directory structure a bit. When you extract the zip, say apache-maven-X.x.x-bin.zip, it creates the folder structure as - "apache-maven-3.5.0-bin\apache-maven-3.5.0..."

In my first attempt I had modified this structure by deleting apache-maven-3.5.0-bin folder and bringing apache-maven-3.5.0 structure one folder up. This was causing the problem.

Increasing answered 4/7, 2017 at 10:57 Comment(0)
S
1
  1. Try with echo %path% , if this option doesn't show your M2_HOME and others variable values as directory path, then create a new environment variable lets say PATH, and assign like below:

    PATH=%JAVA_HOME%\bin;%M2_HOME%\bin
    
  2. Add this in variable path=.....;%PATH%

  3. Now open a new cmd, and try to echo %path%
    it will show all thh system path

Now you can check mvn -version it will solve the problem , if not try to restart the system

P.S. as per doc, you should expend your zip distribution in C:\Program Files\Apache Software Foundation. But ideally it doen't matter

Spinal answered 22/8, 2014 at 8:6 Comment(0)
S
1

I'm using Maven 3+ version. In my case everything was fine. But while adding the M2_HOME along with bin directory, I missed the '\' at the end. Previously it was like: %M2_HOME%\bin , which was throwing the mvn not recognizable error. After adding "\" at the end, mvn started working fine. I guess "\" acts as pointer to next folder. "%M2_HOME%\bin\" Should work, if you missed it.

Shoelace answered 19/12, 2017 at 7:13 Comment(0)
S
1

Try setting the path of maven first through command prompt.

setpath.bat Open the cmd from the base window of the batch file.

The rest maven commands can be used once path is set through cmd.

Sonorous answered 31/1, 2018 at 6:24 Comment(0)
B
1

One most important and often overlooked aspect is the %MAVEN_HOME%\bin or %M2_HOME%\bin should be the first thing in the %PATH% environment variable.

Bobodioulasso answered 21/2, 2018 at 7:37 Comment(1)
single-line solution should be in comment.Ri
Q
1

I tried all way finally below step solved the issue .

In the downloaded zip there is file README , in that its mention that for windows

set PATH="c:\program files\apache-maven-3.x.y\bin";%PATH%

create new PATH variable and assign first maven then %PATH%

it worked out for me .

Try It once

Qp answered 29/12, 2021 at 16:43 Comment(0)
R
0

In your Environement variable :

new system variable:

M2_HOME Your mvn directroy "C:\......\bin"

new user variable:

M2 %M2_HOME%

edit the CLASSPATH by adding %M2%

finally open the cmd and write

path=%CLASSPATH%

enjoy

Rudiment answered 9/12, 2014 at 5:21 Comment(0)
P
0

I had this same error but my problem was I had the following:

M2_HOME = C:\Program Files (x86)\Apache Software Foundation\apache-maven-2.2.1;

Which meant my PATH = %M2_HOME%\bin; (etc)

...became C:\Program Files (x86)\Apache Software Foundation\apache-maven-2.2.1;\bin

i.e. a semicolon was where it shouldn't be.

Which I discovered because Michael Ferry suggested using 'ECHO %PATH%' to see what the actual PATH output was.

Penetrance answered 9/3, 2015 at 6:28 Comment(0)
T
0

I had the same problem. But just restarting my computer after setting up the Maven path resolved the issue.

Variable Name: M2_Home Variable Value:C:\Apache\apache-maven-3.3.9

Variable Name: Path Variable Value:C:\ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%JAVA_HOME%\bin\;%M2_HOME%\bin\

Trioxide answered 30/7, 2017 at 10:23 Comment(0)
R
0

I faced similar problems. The article that helped me solve similar issues is by MKyong and is here: ****https://www.mkyong.com/maven/how-to-install-maven-in-windows/**** It is very important to include in maven's path the file that contains the 'bin','boot', 'conf', 'lib' etc. file folders. For example, in my case, the correct path is: C:\Program Files\Apache Software Foundation\maven\apache-maven-3.5.0-bin\apache-maven-3.5.0

Ramiah answered 10/9, 2017 at 15:30 Comment(0)
R
0

For me it was not working since I was editing Path variable in "User variable" and adding it under "System variable" made it work. Hope it helps.

Roberson answered 2/5, 2018 at 6:38 Comment(0)
B
0

For Windows you need to do the following:

  1. Windows and type env

  2. Open the edit environment panel

  3. Click Environment Variables

  4. In the system variables section, double click Path

  5. In the dialog, create a System Variable under Path like below ->

    MVN_HOME: C:\Users<username>\Documents\Project\Software\apache-maven-3.6.3\bin

  6. Open a new command prompt and hit mvn, you should be able to now.

Backgammon answered 14/9, 2020 at 21:55 Comment(0)
Y
0

I also faced the issue. But the problem I faced was due to the location name where the maven was stored on system. The path did contain spaces due to which system was not able to reach the path leading to this issue. The issue got resolved for me when I moved the maven to a location which did not contain any spaces.

Yourself answered 1/4, 2021 at 17:49 Comment(0)
I
0

The existing answers are too complicated. I just fixed the same issue by

scoop install maven

That requires you install scoop the package manager for Windows in the first place.

However I recommend you install the scoop so that everything becomes easy.

Intwine answered 4/9, 2021 at 2:17 Comment(0)
A
0

Yeah so, for me, I fixed it by setting up the M2 variable. MAVEN_HOME, JAVA_HOME and M2_HOME we set up with their paths, but the command, "mvn -verison" was still showing the error. So I inserted one more variable, named, "M2" and then set the path of the maven folder (not the bin of the same) and ran the command in cmd. It worked.

Astra answered 26/4, 2022 at 7:23 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Morsel
I
0

Adding environment variables from command prompt or windows powershell worked for me. I was able to verify the environment variables present using "set" command in command prompt.

Iatrics answered 2/6, 2022 at 9:51 Comment(0)
M
0

Step 1: Just add below in system veriable (change version accordingly)

C:\apache-maven-3.8.6\bin

Step 2: Restart system

Step 3: Check maven version cmd -> mvn -v

enter image description here

Mercymerdith answered 22/5, 2023 at 14:55 Comment(0)
K
0

If you working with Jenkins and any solutions don't work, try it:

  1. Run cmd.exe
  2. Type mvn
  3. If you will see "'mvn' is not recognized as an internal or external command" - try earlier solutions.
  4. But if maven shows any statements...
  5. Type PATH and press Enter
  6. Check if the path to maven is visible in PATH value.
  7. If path to maven is visible - I have no idea :-)
  8. But if path to maven is not visible...
  9. Probably PATH value is to long.
  10. Open My Computer >> Properties >> Advanced system settings >> System Properties (System properties - not User Properties)
  11. Try to shorten PATH - remove duplications, use indirect variables - %...% etc.
  12. Move up "M2_HOME" variable or full maven path to be closer to the beginning of the PATH.
  13. Save PATH etc.
  14. Close cmd.exe window, and open new.
  15. Type PATH and press Enter
  16. If path to maven is not visible go to step 9.
  17. If path to maven is visible - try run your project in Jenkins. I hope it will work :-)
Kasten answered 7/3 at 15:34 Comment(0)
I
-3

You have written three paths above. The first path (path to maven) should be pointing to the bin directory.

Path to Maven: C:\apache-maven-3.1.0\apache-maven-3.1.0\bin;

Below are right. Above path should be corrected.

M2_HOME:C:\apache-maven-3.1.0\apache-maven-3.1.0;

PATH: Other things,C:\Program Files (x86)\Java\jdk1.7.0_40\bin,C:\apache-maven-3.1.0\apache-maven-3.1.0\bin;

Istle answered 19/2, 2016 at 12:6 Comment(1)
PATH mentioned is incorrect, each path should be seperated by ';' as mentioned @Drollery aboveBerck

© 2022 - 2024 — McMap. All rights reserved.