0%

linux下安装maven

下载

官网下载,地址如下:
https://maven.apache.org/download.cgi

解压

在自己的环境安装目录下解压:

1
tar -zxvf apache-maven-3.6.2-bin.tar.gz

配置更改

更改maven配置为可选项

1
2
$ cd apache-maven-3.6.2/
$ vim conf/settings.xml

自定义本地仓库位置:

1
<localRepository>~/program-file/apache-maven-3.6.2/repository</localRepository>

自定义镜像仓库:

1
2
3
4
5
6
7
8
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>

自定义默认java版本:

1
2
3
4
5
6
7
8
9
10
11
12
 <profile>
<id>jdk1.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>

环境变量配置

ubuntu18.04

1
sudo vim /etc/profile

添加如下maven的path信息:

1
2
3
# maven
export MAVEN_HOME=/home/lazycece/program-file/apache-maven-3.6.2
export PATH=$PATH:$MAVEN_HOME/bin

生效环境变量:

1
2
3
4
5
6
7
$ source  /etc/profile
$ mvn -version
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T23:06:16+08:00)
Maven home: /home/lazycece/program-file/apache-maven-3.6.2
Java version: 1.8.0_201, vendor: Oracle Corporation, runtime: /home/lazycece/program-file/jdk1.8.0_201/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-65-generic", arch: "amd64", family: "unix"