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 a tad bit frustrating.

After I followed the installation guide, line-by-line, I was given the following error on the command line: “‘mvn’ is not recognized as an internal or external command, operable program or batch file.”

Seriously, I really do hate that error.

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

  • M2_HOME: This is supposed to be 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. i.e. I moved M2_HOME from the user variable section over into the environment variable section. Why this worked? I have absolutely no idea. Maybe somebody with a little more knowledge about Windows will be able to elaborate on this.

Hopefully this saves somebody a few hours of heartache!

This article was posted in Code.