1.官网下载(脚本一键安装拉到最后)
https://maven.apache.org/download.cgi
2.选择对应版本后,右键复制下载链接
wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
3.解压
tar -xvf apache-maven-3.8.1-bin.tar.gz -C /usr/local
4.修改环境变量 vim /etc/profile
,添加以下内容
export MAVEN_HOME=/usr/local/apache-maven-3.8.1
export MAVEN_HOME
export PATH=$PATH:$MAVEN_HOME/bin
5.环境变量生效
source /etc/profile
6.验证
mvn -version
[root@cdh-01 local]# mvn -version
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /usr/local/apache-maven-3.8.1
Java version: 1.8.0_221, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8.0_221/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1127.el7.x86_64", arch: "amd64", family: "unix"
7.一键安装脚本
#!/bin/bash
wget -P /usr/local/ https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
tar -xvf /usr/local/apache-maven-3.8.1-bin.tar.gz -C /usr/local
echo "export MAVEN_HOME=/usr/local/apache-maven-3.8.1" >> /etc/profile
echo "export PATH=\$PATH:\$MAVEN_HOME/bin" >> /etc/profile
source /etc/profile
mvn -version
复制粘贴执行即可