Mac OS X下安装配置maven
-
下载Maven,并解压到一个目录下,如/Users/sibeta/data/software/apache-maven-3.3.9
解压命令:
tar zxvf apache-maven-3.3.9-bin.tar.gz
-
打开Terminal,输入以下命令,设置Maven classpath:
vim ~/.bash_profile
添加以下两行代码,保存并退出:
export M2_HOME = /Users/sibeta/data/software/apache-maven-3.3.9
export PATH=$PATH:$M2_HOME/bin
-
输入以下命令使对bash_profile的修改生效
source ~/.bash_profile
-
输入mvn -v查看Maven是否安装成功
若出现以下异常,参考Error: JAVA_HOME is not defined correctly executing maven解决:
sibetadeMacBook-Pro:bin sibeta$ mvn -v Error: JAVA_HOME is not defined correctly. We cannot execute /Libray/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java
即:
Assuming you use bash shell and installed Java with the Oracle installer, you could add the following to your .bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/jre/bin:$PATH
This would pick the correct JAVA_HOME as defined by the Oracle installer and will set it first in your $PATH making sure it is found.
Also, you don't need to change it later when updating Java.