作为Java开放maven时最常见的工具之一,以前一直都在windows中安装,今天记录下在Linux中安装。
1. 下载
官网地址:https://maven.apache.org/download.cgi
可以得到下载命令:
wget https://mirror.bit.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
2. 解压安装
解压
tar -zxvf apache-maven-3.6.3-bin.tar.gz
创建一个目录
mkdir -p /usr/local/maven3
将解压的项目拷贝过去
cd apache-maven-3.6.3
cp -r * /usr/local/maven3
3. 配置环境变量
vim /etc/profile
在结尾添加
#set mvn
export M2_HOME=/usr/local/maven3
export PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
使配置生效
source /etc/profile
查看是否安装成功:
mvn -v
显示:
Maven home: /usr/local/maven3
Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: /usr/local/java/jdk1.8.0_191/jre
Default locale: en_US, platform encoding: UTF-8
OS name: “linux”, version: “3.10.0-514.26.2.el7.x86_64”, arch: “amd64”, family: “unix”
成功
4. 修改镜像地址
vim /usr/local/maven3/conf/settings.xml
找到标签对,添加一下代码:
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
完成