Mac_OS X下安装和配置Maven

1、下载Maven

Maven官网下载页面:http://maven.apache.org/download.cgi

image.png

清华的镜像:apache-maven-3.6.0-bin.tar.gz

解压后可以放到其他目录,本人是在用户文档目录下新建的Java文件夹存放

2、配置环境变量

打开 终端 输入以下命令:

1
vim ~/.bash_profile

打开.bash_profile文件,在次文件中添加设置环境变量的命令
image.png

1
2
export M2_HOME=~/Documents/MineCode/Java/Maven-3.6.0
export PATH=$PATH:$M2_HOME/bin

添加之后保存并推出,执行以下命令使配置生效:

1
source ~/.bash_profile

3、验证

终端输入

1
mvn -v

配置生效会显示下面的信息

1
2
3
4
5
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T02:41:47+08:00)
Maven home: /Users/liyn/Documents/MineCode/Java/Maven-3.6.0
Java version: 11.0.1, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home
Default locale: zh_CN_#Hans, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.2", arch: "x86_64", family: "mac"

相关链接