Last updated: Apr 4, 2024
Reading timeยท6 min
The error "'mvn' is not recognized as an internal or external command, operable program or batch file" occurs for multiple reasons:
mvn
binary file in your system's PATH
environment variable.java
executable in your system's PATH
environment variable.To resolve the error:
apache-maven-3.8.6-bin.zip
.apache-maven
zip file and
click "Extract all".Alternatively, you can extract the zip
file in the current directory and copy
the apache-maven
folder to your preferred location, e.g. C:\Program Files
.
There is a bin
directory in your apache-maven-X.Y.Z
directory.
The bin
directory contains the mvn
executable file which is run when you
issue mvn
commands using the CLI.
bin
directory to your system's PATH environment variable.mvn
executable to your system's PATH environment variableTo add the path to the mvn
executable in your system's PATH environment
variable:
bin
directory or paste it directly.For me, the path is the following.
C:\Program Files\apache-maven-3.8.6\bin
We are looking for the bin
directory that contains the mvn
executable file.
bin
directory, add it and click on the
"OK" button twice to confirm.You might also have to restart your PC, but that's not always necessary.
Open a new Command Prompt and run the mvn --version
command to make sure the
mvn
executable is accessible.
mvn --version
If the error persists, make sure that:
you don't have any stale CMD, PowerShell or IDE sessions and rerun the
mvn --version
command.
You have a Java Development Kit (JDK) version installed and you have the
java
executable in your PATH.
java -version
If you get an error that java
is not recognized, you have to:
java
executable in your PATH environment variable to be
able to use Apache MavenIf you already have java
installed, scroll down to the "Add the path to the
java
executable in your system's PATH environment variable" subheading.
To install and configure Java on Windows:
java -version
command.java -version mvn --version
java
and mvn
commands, then everything works as expected.If the error persists, you have to set the path to the java
executable in your
system's PATH environment variable.
java
executable in your system's PATH environment variableTo add the path to the java
executable in your system's PATH environment
variable:
The path on my machine is the following:
# ๐๏ธ this is the path on my machine C:\Program Files\Common Files\Oracle\Java\javapath # ๐๏ธ it might also be the following path for you C:\Program Files (x86)\Common Files\Oracle\Java\javapath
java.exe
file because this is the file that is run when you issue java
commands.In your case, the java.exe
file might also be under a path similar to the
following.
# ๐๏ธ your version will likely be different C:\Program Files (x86)\Java\jre1.8.0_351\bin
If you can't find the PATH, try issuing the where java
command.
where java
javapath
folder doesn't contain the jar.exe
file. If you intend to use the jar
command to package multiple files into a single archive, you have to add the bin
directory as well.On my machine, the location that contains the java
executable files is the
following.
C:\Program Files\Java\jdk-19\bin
Notice that the path contains the jdk
version, so your path will likely be
different if your jdk
version differs.
java
executable files, add it and click on
the "OK" button twice.You might also have to restart your PC, but that's not always necessary.
Open a new Command Prompt and run the java -version
command to make sure
java
is installed.
java -version mvn --version
.exe
) files has been added to your system's PATH
environment variable, the mvn
command should work.If the error persists, try restarting your PC to make sure you don't have any
stale CMD, PowerShell or IDE sessions and rerun the mvn --version
command.
To solve the error "'mvn' is not recognized as an internal or external command, operable program or batch file", make sure:
mvn
binary file in your system's PATH environment
variable.java
executable in your system's PATH environment
variable.You can learn more about the related topics by checking out the following tutorials: