27

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?

kdabir
  • 9,623
  • 3
  • 43
  • 45
mre
  • 43,520
  • 33
  • 120
  • 170
  • 2
    I had same problem, but making M2 "system variable" instead of "user variable" solved it – Pshemo Aug 09 '12 at 19:01
  • @Pshemo, If you make your comment an answer, I will accept it. Your suggestion worked, thanks! :D Perhaps someone should let Apache know that...i would imagine a lot of people get initially tripped up with that. – mre Aug 09 '12 at 19:05
  • I was facing the same issue. But it got resolved after changing the System variable name from "M2_HOME" to "MAVEN_HOME" – Gunjan Shah Jul 28 '15 at 07:35
  • Make sure you don't have any syntax errors in the "Path" variable. In my case I had an extra " before my M2_HOME, I removed it and it worked. – Ronny Shibley Aug 02 '15 at 11:45
  • Make sure you download the "Binary tar.gz" version. I had the same issue and realized I downloaded the wrong one. – Jacob Malachowski Mar 05 '15 at 22:19

28 Answers28

29

Way around would be moving M2 from user variables to system variables

Pshemo
  • 122,468
  • 25
  • 185
  • 269
  • 2
    It's not a matter of the user vs. system variables. I personally only use user variables in a work context. – Michael Aug 10 '12 at 04:41
  • @TehHippo True, my answer is not explaining problem but only showing way around it (thats why I posted it as comment first). But I am very interested in how it works for you with user variables. Maybe it is a matter of OS. I am using Win7 64bit ult. What OS are you using? – Pshemo Aug 10 '12 at 09:46
  • 2
    Same here :) Have no problem configuring environment variables under my own account and being able to run Maven. I feel it's cleaner too, because others may use this PC and they don't need my Maven settings. They might also have their own one. – Michael Aug 12 '12 at 22:44
  • in my case I also had to move M2_HOME to system variables as a workaround. I am on Windows 7 Pro sp1 64 bit – eddy ed Nov 14 '13 at 12:09
  • As @eddyed said, I'm on Win 8 64bit and had to move both M2 and M2_HOME to system variables to get it to work. – llanato Oct 22 '14 at 08:06
  • It worked for me after movie M2 from user vraible to system variable – prashant thakre Sep 23 '16 at 11:49
7

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

Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • As I said above, "*I've also made sure to add the user variable `M2` to the `Path` system variable*" – mre Aug 09 '12 at 19:06
  • 2
    I had this problem too, but added the absolute path instead of M2 and it worked no problem. – Reimeus Aug 09 '12 at 19:09
  • 3
    I don't think "user variables" can be added to system variables. The latter would be set first. For example, what if a different user logs in - what would PATH=...%M2%/bin resolve to for them if `M2` is only defined for you? – matt b Aug 09 '12 at 19:18
  • 1
    No problem, not using any variables in PATH itself. – Reimeus Aug 09 '12 at 19:22
4

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.

wondergoat77
  • 1,765
  • 9
  • 32
  • 60
4
  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

nevster
  • 6,271
  • 7
  • 35
  • 42
Deep Shah
  • 198
  • 2
  • 5
3

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.

jonypera
  • 446
  • 2
  • 13
  • 23
2

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%
Ada
  • 97
  • 1
  • 11
2

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.

Kadice
  • 51
  • 1
  • 7
1

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.

Michael
  • 1,014
  • 1
  • 8
  • 23
1

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

Barney
  • 16,181
  • 5
  • 62
  • 76
1

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)

1

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

V P
  • 76
  • 7
1

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.

0

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.

Colby
  • 1
  • 1
0

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

Howard Lee
  • 977
  • 1
  • 11
  • 20
0

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.

prime
  • 14,464
  • 14
  • 99
  • 131
0

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.

kukido
  • 10,431
  • 1
  • 45
  • 52
Brian
  • 1
0

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

Engineer
  • 1,436
  • 3
  • 18
  • 33
0

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
khagler
  • 3,996
  • 29
  • 40
BehroOoz
  • 1
  • 3
0

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.

Mithun
  • 67
  • 1
  • 7
0

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

sneha damle
  • 146
  • 2
  • 3
0

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.

Loran
  • 398
  • 2
  • 8
0

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.

BludShot
  • 301
  • 1
  • 3
  • 16
0

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

Ehsan Khodarahmi
  • 4,772
  • 10
  • 60
  • 87
Rams
  • 1
0

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).

RoundPi
  • 5,819
  • 7
  • 49
  • 75
0

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.

Dinu94
  • 165
  • 1
  • 12
0

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.

0

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.

0

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 
Jules Dupont
  • 7,259
  • 7
  • 39
  • 39
mars
  • 1