Linux安装maven
提前安装JDK
1. 下载
wget https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
2. 解压
tar -zxvf /opt/apache-maven-3.6.3-bin.tar.gz -C /opt/
3. 配置环境变量
- 在/etc/profile中加入
export MAVEN_HOME=/opt/apache-maven-3.6.3
export PATH=$PATH:$MAVEN_HOME/bin
- 重新加载资源:source /etc/profile
- 查看版本号:mvn -version
4. 设置仓库
- 创建文件夹:mkdir /opt/apache-maven-3.6.3/ck
- 编辑配置文件:vim /opt/apache-maven-3.6.3/conf/settings.xml
<!-- settings里添加 -->
<localRepository>/opt/apache-maven-3.6.3/ck</localRepository>
<!-- mirrors里添加 -->
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
5. 命令汇总,脚本
前面3步的命令
#!/bin/bash
tar -zxvf /opt/apache-maven-3.6.3-bin.tar.gz -C /opt/
echo 'export MAVEN_HOME=/opt/apache-maven-3.6.3' >> /etc/profile
echo 'export PATH=$PATH:${MAVEN_HOME}/bin' >> /etc/profile
sudo -s source /etc/profile
mvn -version
6. 参考文章
参考文章1:https://www.cnblogs.com/fuzongle/p/12825048.html
参考文章2:https://blog.csdn.net/qq_35868412/article/details/89471735