Installing Maven on MAC OS

I am setting up my new MAC pro for Java development. As I am new to MAC, I find issues while installing and configuring JAVA_HOME variable. Finally I got the solution and I explained in my JAVA_HOME post that how to configure the variable. In this post I am going to show you how to install Maven on MAC.

What is Maven

Apache Maven is a build tool which helps Java developers in building and managing projects. Here are the few features of Maven,

  1. It makes the build process easy
  2. It provides a uniform build system
  3. It provides quality project information
  4. It allow transparent migration to new features

Installing Maven on Mac OS

Now MAC OS is not coming with default installation of Maven. The time when I am writing this post I am using MacOS 10.12. To verify if the Maven is installed or not on the machine. Open the terminal window and type mvn and hit enter. If you get the message “command not found” then it means Maven is not installed.  Download it from the Apache Maven website. And unzip the folder. Make sure you unzip the file in a proper location. I created a WorkSpace folder in my documents and I move the unzip folder in that. The path on MAC looks like this /Users/waqas80/Documents/WorkSpace/apache-maven-3.3.9 .

Before configuring it make sure you have install JDK on your machine and JAVA_HOME variable is set. You can type java -version  in the terminal window to check if JDK is installed or not.

//

One JDK is set, follow the below steps,

  1. Add M2_HOME environment variable by typing the following command in the terminal window, make sure to give the correct path of Maven unzip folder.
    export M2_HOME=/Users/waqas80/Documents/WorkSpace/apache-maven-3.3.9
    
  2. Next is to add M2 environment variable, type the following command in the terminal window
    export M2=$M2_Home/bin
  3. Next add M2 environment variable to path export PATH=$M2:$PATH

That is it. Maven configuration is completed. To verify the configuration type the following command in the terminal window mvn –version  and you will get the following output. Maven configuration

Installing Maven on Mac simple method

Another simple way of installing Maven on Mac or Linux is, download the maven from the website. Extract the zip file and type the below command in the terminal window,

export PATH=/Users/waqas80/Documents/apache-maven-3.5.0/bin:$PATH

I extract the maven zip file in the documents. Once the path is exported type the following command in the terminal, if you see the below result then it means the maven is successfully configured.

Leave a Reply