1. 下载介质
wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
2. 上传并解压
- 在/usr/local/目录下新建文件夹:maven
- 上传介质到/usr/local/maven/
- 解压:tar -zxvf apache-maven-3.8.1-bin.tar.gz
3. 配置环境变量
# 编辑配置文件
vim /etc/profile
# 在末尾追加
export MAVEN_HOME=/usr/local/maven/apache-maven-3.8.1
export PATH=${PATH}:${MAVEN_HOME}/bin
# 使配置文件生效
source /etc/profile
4. 测试
# 测试
mvn -v
# 返回
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /usr/local/maven/apache-maven-3.8.1
Java version: 1.8.0_291, vendor: Oracle Corporation, runtime: /usr/local/java/jdk1.8.0_291/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1127.18.2.el7.x86_64", arch: "amd64", family: "unix"
# 查询MAVEN_HOME
echo $MAVEN_HOME
# 返回
/usr/local/maven/apache-maven-3.8.1
5. 修改配置文件
# 新建仓库存在目录
mkdir /usr/local/maven/repository
# 编辑配置文件
cd /usr/local/maven/apache-maven-3.8.1/conf/
vim settings.xml
# 指定本地仓库路径
<localRepository>/usr/local/maven/repository</localRepository>
# 配置阿里云镜像仓库
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>