Dec 62016

ADM

How to install maven on macOS

  • December 6 2016
  • ADM

 

 

How to install maven on macOS - maven

 

To install maven on macOS follow the next steps. This should work for any version of macOS and maven.

To check first if there is any version installed, run the command:

$ mvn -version

if the output is

bash: mvn: command not found

you need to install maven.

Step1 - Download

From Download page, get the latest version (currently 3.3.9) of the binary file.

Step2 - Move the archive to destination folder (OPTIONAL)

I want to install maven on /usr/local

$ sudo mv apache-maven-3.3.9-bin.tar.gz /usr/local

this command will move the file to /usr/local

Step3 - Extract

To extract run the command:

$ sudo tar -xvf apache-maven-3.3.9-bin.tar.gz 

The command will extract to the current folder.

Step4 - Delete the archive (OPTIONAL)

run the following command:

$ sudo rm apache-maven-3.3.9-bin.tar.gz

Step5 - Path Config

To have access to maven from any directory need to configure M2_HOME and added the bin directory to path

For this add the following lines to the ~/.bash_profile file using vim editor:

export M2_HOME=/usr/local/apache-maven-3.3.9

export PATH=$PATH:$M2_HOME/bin

In order to have the effect, you need to restart the terminal.

Step6 - Test

To check run the version command.

mvn -version

Output

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)

Maven home: /usr/local/apache-maven-3.3.9

Java version: 1.8.0_112, vendor: Oracle Corporation

Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre

Default locale: en_GB, platform encoding: UTF-8

OS name: "mac os x", version: "10.12.1", arch: "x86_64", family: "mac"