[Solution] : ‘mvn’ is not recognized as an internal or external command

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

  1. Download Maven:
  2. 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).

Step 2: Set Up Environment Variables

For Windows

  1. 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).
  2. 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).
  3. Apply Changes:
    • Click OK to close all dialog boxes.

For macOS/Linux

  1. Open Terminal.
  2. Edit your profile (e.g., .bash_profile, .bashrc, or .zshrc):
nano ~/.bash_profile  # or ~/.bashrc or ~/.zshrc depending on your shell
  1. 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.

  1. Save and Exit: (Press CTRL + X, then Y, and Enter in nano).
  2. Apply the changes:
source ~/.bash_profile  # or source ~/.bashrc or source ~/.zshrc

Step 3: Verify the Installation

  1. Open a new command prompt or terminal.
  2. 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!

Article Contributors

  • Ishan Dev Shukl
    (Author)
    SDET Manager, Nykaa

    With 13+ years in SDET leadership, I drive quality and innovation through Test Strategies and Automation. I lead Testing Center of Excellence, ensuring high-quality products across Frontend, Backend, and App Testing. "Quality is in the details" defines my approach—creating seamless, impactful user experiences. I embrace challenges, learn from failure, and take risks to drive success.

  • Captain Jarhead
    (Reviewer)
    Chief Java Officer, QABash

    Captain Jarhead is a fearless Java expert with a mission to conquer bugs, optimize code, and brew the perfect Java app. Armed with a JVM and an endless supply of caffeine, Captain Jarhead navigates the wild seas of code, taming exceptions and turning null pointers into smooth sailing. A true master of beans, loops, and classes, Captain Jarhead ensures no bug escapes his radar!

Never Miss a Story

Weekly – Straight to Your Inbox!

We don’t spam! privacy policy

Leave a Reply

Scroll to Top