欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

linux下安装maven

程序员文章站 2022-06-18 16:50:16
...

下载

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

解压

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

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

配置更改

更改maven配置为可选项

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

自定义本地仓库位置:

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

自定义镜像仓库:

<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版本:

 <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

sudo vim /etc/profile

添加如下maven的path信息:

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

生效环境变量:

$ 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"