Mvn is not recognized as an internal or external command in eclipse terminal

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!

Learn to install Maven on a Windows operating system. In this maven installation guide, we are installing Maven on a Windows 11 machine. The steps are the same for a Windows 10 machine as well.

1. Windows Environmant Variables

Maven is a build and dependency management tool for Java applications development. Just like many other Java development tools, Maven is not installed as a Windows service, rather it is configured using the Windows environment variables.

Mvn is not recognized as an internal or external command in eclipse terminal
Windows environment variables option

2. Steps to Install and Configure Maven

Follow the steps needed to install maven on the windows operating system.

2.1. Verify Installed JDK and ‘JAVA_HOME’ Environment Variable

We must have Java installed on our computer and the JAVA_HOME must be set in the environment variables.

To install java, download JDK installer and install Java. Then add/update the JAVA_HOME variable to the JDK installation folder.

On my computer, JAVA_HOME is pointing to the JDK 17 installation folder.

Mvn is not recognized as an internal or external command in eclipse terminal
JAVA_HOME Variable

2.2. Download and Extract Maven Zip File

We can download the latest version from Maven from the official website. Now we need to extract the downloaded zip file in any location.

I have extracted it on C:\devsetup\maven. You can choose your own folder location.

Mvn is not recognized as an internal or external command in eclipse terminal
Maven Installation folder

Let us briefly discuss what these directories contain:

  • The bin folder contains the batch files and shell scripts to run Maven on various platforms.
  • The boot folder contains the jars required for Maven to start.
  • The conf folder contains the default settings.xml file used by Maven.
  • The lib folder contains the libraries used by Maven. It also contains an ext folder in which third-party extensions, which can extend or override the default Maven implementation, can be placed.

2.3. Add M2_HOME Environment Variable

Now add the M2_HOMEto windows environment variables. The value will be the installation location on your computer.

Note that it is an optional step, yet it is highly recommended. Many external IDEs and tools rely on M2_HOME variable to work with Maven.

Mvn is not recognized as an internal or external command in eclipse terminal
Add M2_HOME Environment Variable

2.4. Include ‘bin’ directory in PATH Variable

To run Maven commands from the console, windows should be able to locate the Maven batch files. Update the PATH variable with '%M2_HOME%\bin' directory.

Mvn is not recognized as an internal or external command in eclipse terminal
Add Path to Maven bin folder

3. Verify Maven Installation

Maven installation is complete. Now, let’s test it from the windows command prompt.

  1. Go to start menu and type cmd in application location search box.
  2. Press ENTER. A new command prompt will be opened.
  3. Type mvn -version in command prompt and hit ENTER.
$ mvn -version

The mvn command runs this batch file mvn.bat from bin folder of the Maven installation location. That’s why we added the the location to PATH environment variable.

After checking JAVA_HOME and any optional arguments (Maven_OPTS), the batch file runs its main class org.codehaus.plexus.classworlds.launcher.Launcher.

Mvn is not recognized as an internal or external command in eclipse terminal
Verify Maven Installation

This should show the Maven version information, path to Maven bin folder and installed Java version.

If you face any error in the command prompt then please cross-check all the above steps.

Happy Learning !!

Join 7000+ awesome developers, like you!

How do you fix mvn is not recognized as an internal or external command?

5>mvn --version 'mvn' is not recognized as an internal or external command, operable program or batch file..
Extract the maven zip file..
Open the environment variable and in user variable section click on new button and make a variable called MAVEN_HOME and assign it the value of bin path of extracted maven zip..

Why Maven is not showing in command prompt?

Open command line, type "set" and hit enter, it will give you list of environment variables. Search for M2_HOME and JAVA_HOME. If they don't exist then you need to right click My Computer--> Properties --> Advanced --> Environment variables. Add M2_HOME and JAVA_HOME environment variables there.

How do I run a Maven project in Terminal?

Running a Java Maven Project from the Command Line(CLI) - With Example Code.
Create a new maven project..
Compile and execute your Java code into an executable JAR file..
Add unit test for your code..

How do I know if Maven is installed on Windows?

Once Maven is installed, you can check the version by running mvn -v from the command-line. If Maven has been installed, you should see something resembling the following output. If you see this output, you know that Maven is available and ready to be used.