If you’re seeing the message 'mvn' is not recognized as an internal or external command
, it means that Maven is not installed on your system or its path is not set correctly. Here’s how to fix that:
Step 1: Install Maven
- Download Maven:
- Go to the Apache Maven download page.
- Download the binary zip file (e.g.,
apache-maven-x.x.x-bin.zip
).
- Extract Maven:
- Extract the downloaded zip file to a location on your system (e.g.,
C:\Program Files\Apache\maven-x.x.x
on Windows or/opt/maven
on Linux/Mac).
- Extract the downloaded zip file to a location on your system (e.g.,
Step 2: Set Up Environment Variables
For Windows
- Set
MAVEN_HOME
:- Right-click on This PC or Computer on your desktop or in File Explorer and select Properties.
- Click on Advanced system settings.
- Click on Environment Variables.
- Under System Variables, click New.
- Variable name:
MAVEN_HOME
- Variable value: Path to your Maven folder (e.g.,
C:\Program Files\Apache\maven-x.x.x
).
- Variable name:
- Update
PATH
Variable:- In the same Environment Variables window, find the
Path
variable in the System Variables section and select it. - Click Edit and add a new entry for Maven’s
bin
directory (e.g.,C:\Program Files\Apache\maven-x.x.x\bin
).
- In the same Environment Variables window, find the
- Apply Changes:
- Click OK to close all dialog boxes.
For macOS/Linux
- Open Terminal.
- Edit your profile (e.g.,
.bash_profile
,.bashrc
, or.zshrc
):
nano ~/.bash_profile # or ~/.bashrc or ~/.zshrc depending on your shell
- Add the following lines:
export MAVEN_HOME=/path/to/apache-maven-x.x.x
export PATH=$MAVEN_HOME/bin:$PATH
Replace /path/to/apache-maven-x.x.x
with the actual path where you extracted Maven.
- Save and Exit: (Press
CTRL + X
, thenY
, andEnter
innano
). - Apply the changes:
source ~/.bash_profile # or source ~/.bashrc or source ~/.zshrc
Step 3: Verify the Installation
- Open a new command prompt or terminal.
- Run the following command:
mvn -v
If Maven is installed correctly, you should see the version information displayed.
Conclusion
Once Maven is set up, you’ll be able to use the mvn
command to run your tests and manage your project. If you have any further questions or issues, feel free to ask!