43

I get the following error when I type the command mvn --version:

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

I have also followed this but still I am unable to get the work done.

when I type this command echo %M2_HOME% I get path printed as D:\Program Files\apache-maven-3.0.4 when I type 'echo %M2%' I get the path printed as D:\Program Files\apache-maven-3.0.4\bin

Environment : Windows XP

Community
  • 1
  • 1
Java Questions
  • 7,813
  • 41
  • 118
  • 176
  • 2
    The bin folder needs to be set on your `%PATH%` environment variable. The other variables are irrelevant in order to execute the batch from the shell. Have a look at `%PATH%` – Andreas Dolk Dec 04 '12 at 07:28
  • 4
    make sure to relanuch your cmd window after changing path – Denis Tulskiy Dec 04 '12 at 07:28
  • 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. – shuchita khurana May 10 '18 at 08:34
  • None of mentioned solutions helped me. It turns out that I had to move modify `PATH` variable and move %JAVA_HOME%\bin before %M2_HOME%\bin – Daniel Stradowski Oct 24 '18 at 07:03

3 Answers3

39

On my Windows 7 machine I have the following environment variables:

  • JAVA_HOME=C:\Program Files\Java\jdk1.7.0_07

  • M2_HOME=C:\apache-maven-3.0.3

On my PATH variable, I have (among others) the following:

  • %JAVA_HOME%\bin;%M2_HOME%\bin

I tried doing what you've done with %M2% having the nested %M2_HOME% and it also works.

wulfgarpro
  • 6,666
  • 12
  • 69
  • 110
  • nicely done. Do remember to check whether you are using appropriate java version e.g. jdk 1.8 and JAVA_HOME is updated to use appropriate jdk if you have multiple installed. – Osaid Mar 02 '17 at 10:41
  • Whole time I was typing **maven -version**,instead of **mvn -version** :P – Mehraj Malik Mar 09 '17 at 06:38
26

Make sure you have your maven bin directory in the path and the JAVA_HOME property set

kirschmichel
  • 903
  • 1
  • 8
  • 14
  • 2
    `JAVA_HOME` is not required in order to get `mvn --version` to run. It is required for compilation, but that's later. – Andreas Dolk Dec 04 '12 at 07:20
  • 2
    yes maven bin directory is there in the path specified. also i agree with Andreas_D :) – Java Questions Dec 04 '12 at 07:22
  • @kirschmichel I have setup all(JAVA_HOME, M2, M2_HOME)and updated in path, but still I have getting same error 'mvn' is not recognized as an internal or.... – Charan Ghate Feb 23 '16 at 10:25
12

Add maven directory /bin to System variables under the name Path.

To check this, you can echo %PATH%

Jaanus
  • 16,161
  • 49
  • 147
  • 202