1. 下载maven
curl -O https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.zip
2. 解压缩
unzip apache-maven-3.8.6-bin.zip
3. 移动目录
mv apache-maven-3.8.6 /usr/local/bin/
4. 创建软链接
ln -sv /usr/local/bin/apache-maven-3.8.6/bin/mvn /bin/
5. 创建环境变量
cat >> /etc/profile <<'EOF'
# Maven 3.6.3
export M2_HOME=/usr/local/bin/apache-maven-3.8.6
export PATH=$PATH:$M2_HOME/bin
EOF
6. 配置生效
source /etc/profile
7. 验证maven
[root@localhost opt]# mvn -v
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /usr/local/bin/apache-maven-3.8.6
Java version: 1.8.0_202, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8.0_202-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-693.el7.x86_64", arch: "amd64", family: "unix"
8. 修改maven源
mkdir -p /opt/maven/repo
vi /usr/local/bin/apache-maven-3.8.6/conf/settings.xml
<localRepository>/opt/maven/repo</localRepository>
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
END