mvn command not found - Mac

Page content

How to Install ‘mvn’ Command on Mac

In this tutorial, we will guide you through the process of installing the ‘mvn’ command on your Mac. The ‘mvn’ command is a commonly used tool in Java development, as it is part of Apache Maven, a popular build automation tool primarily used for Java projects. Maven simplifies the build process by managing project dependencies and providing a uniform build system.

What is the ‘mvn’ Command?

The ‘mvn’ command is the primary command-line interface for Apache Maven. It allows developers to execute various build tasks, such as compiling source code, running tests, packaging applications, and managing project dependencies. Maven uses XML configuration files to define project settings and build processes, making it easier to maintain and share project configurations across different environments.

Installation Steps

To install the ‘mvn’ command on your Mac, follow these steps:

  1. Check Java Installation: Before installing Maven, ensure that Java is installed on your Mac. Maven requires Java to run. You can check if Java is installed by opening a terminal window and running the command java -version.

  2. Download Maven: Visit the Apache Maven download page and download the latest version of Maven for Mac. Choose the binary tar.gz file.

  3. Extract Maven: Once the download is complete, navigate to the directory where the Maven tar.gz file is located and extract it using the following command:

    tar -xf apache-maven-<version>.tar.gz
    
  4. Set Environment Variables: To use Maven from any directory in the terminal, you need to set the M2_HOME and PATH environment variables. Add the following lines to your ~/.bash_profile or ~/.zshrc file:

    export M2_HOME=/path/to/apache-maven-<version>
    export PATH=$PATH:$M2_HOME/bin
    
  5. Verify Installation: Open a new terminal window and run the command mvn -version to verify that Maven has been successfully installed on your Mac.

Conclusion

Congratulations! You have successfully installed the ‘mvn’ command on your Mac. Now you can use Apache Maven to streamline your Java project builds and manage dependencies efficiently.


The Importance of Open Source Software

Open source software plays a crucial role in the world of technology by fostering collaboration, innovation, and transparency. It empowers developers to access, modify, and contribute to software freely, leading to the creation of robust and community-driven solutions. By embracing open source software like Apache Maven, we not only benefit from the features and capabilities it offers but also contribute to a thriving ecosystem of shared knowledge and resources. Open source software embodies the spirit of collective intelligence and democratizes access to technology, shaping a more inclusive and collaborative future for software development.