官方下载地址:http://maven.apache.org/download.cgi

下载:https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

解压之后,复制目录:/Users/onns/Downloads/java/apache-maven-3.6.3

因为系统更新后,命令行从bash换成了zsh所以环境变量文件也改了:.zshrc

1
2
3
echo 'export M2_HOME=/Users/onns/Downloads/java/apache-maven-3.6.3/bin' >> .zshrc
echo 'export MAVEN_HOME=/Users/onns/Downloads/java/apache-maven-3.6.3' >> .zshrc
echo 'export PATH=$MAVEN_HOME/bin:$PATH' >> .zshrc

让环境变量生效:

1
source .zshrc

测试:

1
2
3
4
5
6
$ mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/onns/Downloads/java/apache-maven-3.6.3
Java version: 13.0.2, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home
Default locale: en_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.5", arch: "x86_64", family: "mac"

#修改镜像源

参照阿里云的使用指南:https://maven.aliyun.com/mvn/guide

打开$MAVEN_HOME/conf/settings.xml

<mirrors></mirrors>标签中添加mirror子节点:

1
2
3
4
5
6
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>

#配置本地仓库

打开$MAVEN_HOME/conf/settings.xml

1
2
3
4
5
6
7
8
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->

<localRepository>/Users/onns/Downloads/java/apache-maven-3.6.3/repo</localRepository>

#相关链接