下载解压
- 下载maven
wget https://repo.huaweicloud.com/apache/maven/maven-3/3.9.8/binaries/apache-maven-3.9.8-bin.tar.gz
- 解压maven
tar -zxvf apache-maven-3.9.8-bin.tar.gz
-
变更maven文件夹名称(非必须)
mv apache-maven-3.9.8 maven
换源
替换settings.xml内标签中的内容(位于maven/conf/setting.xml)
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
配置环境变量
- 编辑配置文件
vim /etc/profile
- 在profile文件末尾环境变量
MAVEN_HOME=/tools/maven/maven
PATH=$PATH:$MAVEN_HOME/bin
export MAVEN_HOME
- 重新加载配置文件
source /etc/profile
- 查看maven版本
[root@hecs-166225 maven]# mvn -v
Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: /tools/maven/maven
Java version: 1.8.0_412, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.412.b08-1.el7_9.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1160.108.1.el7.x86_64", arch: "amd64", family: "unix"