liunx下安装maven

133 阅读1分钟

安装 maven 环境前,需要先安装 java 环境,笔者这里已经成功安装 java 环境,如果没有安装 java 环境,可以参考:linux下安装jdk

一、maven 官网下载安装包

maven 官网地址:maven.apache.org/download.cg…

image.png

下载完成后,上传到 linux

image.png

二、安装maven

1.创建maven文件夹

mkdir /usr/local/soft/maven

2.解压

tar -zxvf apache-maven-3.8.6-bin.tar.gz -C /usr/local/soft/maven

3.创建 maven 资源库目录

mkdir /usr/local/soft/maven/repository

4.编辑 settings.xml 文件

vim /usr/local/soft/maven/apache-maven-3.8.6/conf/settings.xml

删除原有全部内容

:1,$d

新的配置内容

修改了资源库位置,添加了阿里云国内镜像

<?xml version="1.0" encoding="UTF-8"?>
 
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
 
  <localRepository>/usr/local/soft/maven/repository</localRepository>
  
  <pluginGroups>
  </pluginGroups>
 
  <proxies>    
  </proxies>
 
  <servers>
  </servers>
 
  <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>
  </profiles>
</settings>

三、配置环境变量

vim /etc/profile

1.添加 maven 环境变量内容

MAVEN_HOME=/usr/local/soft/maven/apache-maven-3.8.6
PATH=$MAVEN_HOME/bin:$PATH
export MAVEN_HOME PATH

2.重新加载配置文件

source /etc/profile

3.测试

mvn -version

image.png

安装完毕!