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

Viewed 123964

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?

28 Answers

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.

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.

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.

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 
Related