Linux 下配置 maven 环境

下载 maven 二进制

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

或者直接在 Linux 上通过 wget 下载:

1
wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz

配置环境变量

解压二进制后 tar -xvf apache-maven-3.8.6-bin.tar.gz,打开文件 vi ~/.bashrc,添加下面三行配置:

1
2
3
export M2_HOME=/root/apache-maven-3.8.6
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

最后更新下:source ~/.bashrc

通过 mvn --version 命令测试:

1
2
3
4
5
6
root@PAOPAO:~# mvn --version
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /root/apache-maven-3.8.6
Java version: 1.8.0_342, vendor: Private Build, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-29-generic", arch: "amd64", family: "unix"