centos6.9安装maven3.6.3

  在root下进入/usr/lib目录,从官网下载最新版本3.6.3的tar包,解压:

[root@VM-0-14-centos ~]# cd /usr/local
[root@VM-0-14-centos local]# wget https://mirror.bit.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
--2020-10-19 10:44:39--  https://mirror.bit.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
Resolving mirror.bit.edu.cn... 202.204.80.77, 219.143.204.117, 2001:da8:204:1205::22
Connecting to mirror.bit.edu.cn|202.204.80.77|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9506321 (9.1M) [application/octet-stream]
Saving to: “apache-maven-3.6.3-bin.tar.gz”

100%[==============================================================================>] 9,506,321   12.8M/s   in 0.7s    

2020-10-19 10:44:40 (12.8 MB/s) - “apache-maven-3.6.3-bin.tar.gz” saved [9506321/9506321]

[root@VM-0-14-centos local]# tar xvf apache-maven-3.6.3-bin.tar.gz

  删除压缩包,配置环境变量:

[root@VM-0-14-centos local] rm -f apache-maven-3.6.3-bin.tar.gz
[root@VM-0-14-centos local] cd /etc/profile.d
[root@VM-0-14-centos profile.d]# vim maven.sh

M2_HOME=/usr/local/apache-maven-3.6.3
PATH=$PATH:$M2_HOME/bin
export M2_HOME PATH

  让以上配置的maven环境变量生效:

[root@VM-0-14-centos profile.d]# source /etc/profile
[root@VM-0-14-centos profile.d]# echo $M2_HOME
/usr/local/apache-maven-3.6.3
[root@VM-0-14-centos profile.d]# mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/apache-maven-3.6.3
Java version: 1.8.0_265, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.265.b01-0.el6_10.i386/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-696.el6.i686", arch: "i386", family: "unix"

   打完收工,最后配置一下setting文件:

[root@VM-0-14-centos profile.d]# cd ~
[root@VM-0-14-centos ~]# vi /usr/local/apache-maven-3.6.3/conf/settings.xml 

  因为我之前设置过nexus的私服(参见使用nexus3.19搭建自己的maven私服 ),直接把那个setting文件拿过来用即可:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository>E:/Users/wulf/.m2/repository</localRepository>

    <mirrors>
        <mirror>
            <id>nexus</id>
            <name>nexus repository</name>
            <url>http://111.11.11.11/repository/nexus-group</url>
            <mirrorOf>*</mirrorOf>
        </mirror>
    </mirrors>

    <!-- 激活配置 -->
    <activeProfiles>       
        <activeProfile>nexus</activeProfile>
    </activeProfiles>    
    <profiles>
        <profile>
            <id>nexus</id>
            <repositories>
                <repository>
                    <id>central</id>      
                    <url>http://111.11.11.11:17407/repository/aliyun</url>                    
                    <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></snapshots>                    
                </repository>               
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>central</id>      
                    <url>http://111.11.11.11:17407/repository/aliyun</url>                    
                    <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></snapshots>    
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>


    <servers>
        <server>
            <id>nexus-releases</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
        <server>
            <id>nexus-snapshots</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server> 
    </servers>

</settings>
原文地址:https://www.cnblogs.com/wuxun1997/p/13839087.html