下载软件包

# 20180921最新安装包版本3.5.4,下载二进制包,解压即可使用
mkdir -p /server/tools
cd /server/tools/
wget https://mirrors.cnnic.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz --no-check-certificate

解压安装maven软件包

tar -xf apache-maven-3.5.4-bin.tar.gz 
mv apache-maven-3.5.4 /usr/local/maven
# 与jenkins联合使用时,jenkins会到/usr/bin/下找mvn命令,如果没有回报错
ln -s /usr/local/maven/bin/mvn  /usr/bin/mvn    
ll /usr/local/maven/
ll /usr/bin/mvn

配置环境变量

echo " ">>/etc/profile
echo "# Made for mvn env by chenqi on $(date +%F)">>/etc/profile
echo 'export MAVEN_HOME=/usr/local/maven'>>/etc/profile
echo 'export PATH=$MAVEN_HOME/bin:$PATH'>>/etc/profile
tail -4 /etc/profile
source /etc/profile
echo $PATH

查看安装的mvn版本号

# 查看mvn工具的位置/usr/local/maven/bin/mvn
which mvn
# 查看maven版本
mvn -version

结果示例

[root@CentOS75 conf]# which mvn      
[root@CentOS75 conf]# mvn -version    
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-18T02:33:14+08:00)
Maven home: /usr/local/maven
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8.0_181-amd64/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-862.11.6.el7.x86_64", arch: "amd64", family: "unix"

maven打包命令

mvn package -Dmaven.test.skip=true -Dmaven.javadoc.skip=true