Fixing “mvn not recognized as an internal or external command” error

Apache Maven is a software project management tool that is supposed to “make the build process easy.”

Unfortunately for me, the installation process for Maven was pretty frustrating.

After I followed the installation guide line-by-line, the command line printed out the following error:

“‘mvn’ is not recognized as an internal or external command, operable program or batch file.”

Honestly, I really do hate that error.

I followed the Maven installation guide, word-for-word and I even checked the user and environment variables multiple times, just to make sure that I hadn’t messed anything up by making a typo or something.

However, all of the user variables were correct.

For reference:

  • M2_HOME: This is a user variable that points towards your Maven directory.
  • M2: This is an environment variable that points towards Maven’s bin folder. Example: $M2_HOME/bin
  • JAVA_HOME: Points towards the directory of your JDK.

Frustratingly enough, none of this seemed to work on my Windows 7 machine.

The fix?

Basically, I just made sure that all of variables listed above existed as environment variables.

In other words, I moved M2_HOME from the user variable section over into the environment variable section.

Why this worked? I have absolutely no idea. Maybe someone with a little more knowledge about Windows will be able to elaborate on this.

Hopefully this saves someone a few headaches!

This article was posted in Sysadmin on June 4, 2014.