windows安装
一、安装本地Maven
1.官网下载
- 官网地址:https://maven.apache.org/download.cgi
- 左侧选择Download
- 下载
最新版本下载:
以往版本下载:
- 下载完成后,选择一个路径进行解压
- 配置path环境变量
- win+R 运行cmd 输入 mvn -version,如图所示则配置成功
二、配置settings文件
- D:\apache-maven-3.6.1\conf下找到settings文件,打开
- 复制第55行到注释外,设置本地仓库地址
- 配置镜像。因为国外的服务器下载jar包很慢所以我们改为阿里云服务器(大约在150行左右)
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<!--配置远程仓库镜像-->
<!--因为国外的服务器下载jar包很慢所以我们改为阿里云服务器-->
<!-- 阿里云仓库 -->
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
</mirrors>
- 最后配置jdk,也要夹在两个profiles标签之间(我这里使用的为jdk8)
<!-- java版本 -->
<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>
- 配置完成,在命令行输入mvn help:system测试,看到下载链接里面是ailiyun的链接表示配置成功
linux安装maven
第一步:上传或下载安装包
cd/usr/local
apache-maven-3.8.4-bin.tar.gz
第二步:解压安装包
tar -zxvf apache-maven-3.8.4-bin.tar.gz
第三步:建立软连接
ln -s /usr/local/apache-maven-3.8.4/ /usr/local/maven
第四步:修改环境变量
vim /etc/profile
export MAVEN_HOME=/usr/local/maven
export PATH=$PATH:$MAVEN_HOME/bin
通过命令source /etc/profile让profile文件立即生效
source /etc/profile
第五步:测试是否安装成功
mvn –v