Linux下安装maven(mvn命令)

1.准备工作

1)maven的安装运行以来Java环境,需要预先安装,具体Java安装方法可以参考我的另一篇博文:

linux下yum安装jdk1.8(rpm包)和tomcat-8.5

2)maven软件包下载地址:

Index of /apache/maven

2.安装maven

1)下载软件包

# 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

2)解压安装maven软件包

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

3)配置环境变量

echo " ">>/etc/profile
echo "# 添加maven">>/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

 4)查看安装的mvn版本号

which mvn
mvn -version

3.配置maven私有库

# 编辑maven配置文件修改私有库的配置

cd /usr/local/maven/conf/
cp settings.xml settings.xml.ori
vim /usr/local/maven/conf/settings.xml
--------- setting标签里设置本地仓库的存储位置 ----------
  /usr/local/maven/mavenlib        
---------- mirror标签里配置Maven 镜像地址 --------------
    
      nexus
      *
      mynexus
      http://192.168.1.9:18081/repository/maven-public/
    
------------------- 配置私服地址  ---------------------
     
       nexus
       
         
           nexus
                Nexus
           http://192.168.1.9:18081/repository/maven-public/
           true
           true
         
       
       
         
           nexus
             Nexus
             http://192.168.1.9:18081/repository/maven-public/
             true
             true
         
       
     
---------------------

你可能感兴趣的:(maven,linux,java)