下载maven安装包
wget http://mirrors.hust.edu.cn/apache/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.tar.gz
解压
tar zxf apache-maven-3.1.1-bin.tar.gz
移动maven文件夹(个人习惯)
mv apache-maven-3.1.1 /usr/local/maven3
vi /etc/profile配置环境变量,在底部添加:
export M2_HOME=/usr/local/maven3
export PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
保存退出后运行下面的命令使配置生效,或者重启服务器生效。
source /etc/profile
验证版本
mvn -v
如果安装正确就可以看到Maven的版本了。如果提示以下错误,请检查/etc/profile中PATH环境变量值中是否包含Maven可执行文件的路径,以及是否使该配置生效。
-bash: mvn: command not found
$M2_HOME/bin中的settings.xml需要更改一下,apache的数据源基本下不了包,我这里使用阿里巴巴的数据源。
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<localRepository>/maven</localRepository><!--需要改成自己的maven的本地仓库地址-->
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://maven.oschina.net/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://maven.oschina.net/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile></profiles>
</settings>