Install Maven on Mac

In this post, we will see how to install maven on Mac.

If you are using the latest MacOSX, maven may be built-in and can be found at /usr/share/maven.

Execute below command on terminal to see if you have maven installed.

$mvn –version
-bash: mvn: command not found

If you get -bash: mvn: command not found as output, then maven is not installed on your machine and you need install it manually.

Install maven manually

Download and extract Maven

Go to http://maven.apache.org/download.cgi and download latest version of maven.

After download, go to the downloaded location and extract it.

tar -xvf apache-maven-3.6.3-bin.tar.gz

You will see a folder named apache-maven-3.6.3. You can check its location with pwd command.

$pwd
/Users/apple/Downloads

Update M2_HOME and PATH

You need to update two environment variable M2_HOME and PATH to run maven commands.

Open ~/.bash_profile file

vi ~/.bash_profile

and add below two lines.

export M2_HOME=/Users/apple/Downloads/apache-maven-3.6.3
export PATH=$PATH:$M2_HOME/bin

Verfiy maven installation

Restart the terminal and execute below command again.

$ mvn –version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/apple/Downloads/apache-maven-3.6.3
Java version: 12.0.2, vendor: AdoptOpenJDK, runtime: /Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.2.jdk/Contents/Home
Default locale: en_IN, platform encoding: UTF-8
OS name: “mac os x”, version: “10.13.6”, arch: “x86_64”, family: “mac”

As you can see, maven is successfully installed on your machine. You can go ahead and create maven based project now.

Install maven using Homebrew

You can install maven using Homebrew. It is fairly straight forward.

If you do not have Homebrew installed on your mac, you can use below command to install it.

/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)”

Once Homebrew is installed, you can run below command to install maven.

$ brew install maven

That’s all about how to install maven on Mac.

Related Posts

  • 28 March

    Generate source code jar for Maven based project

    Table of ContentsDeploy the jarCheck the local repository In this tutorial, we will see how to generate source code jar for maven based project. If you have simple java project, then you need to convert it maven project. Sometimes, you need to pack source code with your project jar. This is extremely useful when people […]

  • 21 March

    Run single test in maven

    Table of ContentsRun all testcaseRun all testcases from a test classRun specific test method from a test classRun multiple test methods from a test class In this post, we will see how to run single test in maven. If you want to execute all the Junit testcases in maven. You can run it below command. […]

  • 21 March

    Skip tests in maven

    Table of ContentsUsing maven.test.skip=trueUsing SkipTestsSkip tests in Maven in eclipseConclusion In this tutorial, we will see how to skip tests in maven. It is not a good idea to skip junit tests while building project in maven but sometimes, you may need to skip it for building new code and want to test it quickly. […]

  • 23 August

    log4j properties file example

    Logging is essential part of programming. It helps developer to track code workflow and fix bugs efficiently. If we get any issue in the code, we check logs for that workflow or functionality. Log4j is fast , reliable logging framework and can be easily integrated with the code. It is possible to enable logging at […]

  • 23 May

    log4j xml configuration example

    Logging is essential part of programming. It helps developer to track code workflow and fix bugs efficiently. If we get any issue in the code, we check logs for that workflow or functionality. Log4j is fast , reliable logging framework and can be easily integrated with the code. It is possible to enable logging at […]

  • 20 February

    Log4j Maven configuration example

    Logging is essential part of programming. It helps developer to track code workflow and fix bugs efficiently. If we get any issue in the code, we check logs for that workflow or functionality. Log4j is fast , reliable logging framework and can be easily integrated with the code. It is possible to enable logging at […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.