Mac configure Maven3

Make Sure JAVA_HOME has been setup

Before we configure Maven, we need to make sure JAVA_HOME is setup properly.

1
echo $JAVA_HOME

if there is nothing comes out, that means you didn’t set JAVA_HOME up before. You can follow the instructions as follow. If you have configured it correctly, just ignore it.

1
2
3
4
5
6
7
sudo vi /etc/profile(or ~/.bash_profile or /etc/bashrc)
//add the content into file
export JAVA_HOME=$(/usr/libexec/java_home)
source /etc/profile

echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home

Set up Maven

We can download the latest version of maven, then unzip to the installing folder(/usr/local/opt/maven3). Later, we also need to register maven into environment variable files.

1
2
3
4
5
6
7
8
9
10
11
sudo vi /etc/profile
//add the content into file
export M2_HOME=/usr/local/opt/maven3/apache-maven-3.3.9
export PATH=$M2_HOME/bin:$PATH
source /etc/profile

mvn -v
Java version: 1.8.0_66, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.10", arch: "x86_64", family: "mac"