Linux (Ubuntu)上面安装maven

时间:2021-07-08 06:32:53

1 首先检查linux上是否有maven

mvn -v

或者mvn -version

如果没有安装,提示如下:

ubuntu@ip-172-31-29-46:~$ mvn -v
The program 'mvn' can be found in the following packages:
 * maven
 * maven2
Try: sudo apt-get install <selected package>

如果有安装,提示如下:

cfj@cfj-virtual-machine:/opt$ mvn -v
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-18T02:33:14+08:00)
Maven home: /opt/apache-maven-3.5.4
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-8-oracle/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-32-generic", arch: "amd64", family: "unix"

2 下载maven  http://maven.apache.org/download.cgi

Linux (Ubuntu)上面安装maven

选择.tar.gz文件

3 将下载的文件上传到linux 的/opt 文件夹下面

解压该压缩文件:sudo tar -zxvf apache-maven-3.5.4-bin.tar.gz

解压之后得到apache-maven-3.5.4/ 文件夹

Linux (Ubuntu)上面安装maven

4 配置环境变量

sudo vi /etc/profile

添加

export M2_HOME=/opt/apache-maven-3.5.4
export PATH=$PATH:$M2_HOME/bin

添加完成之后重启环境变量使之生效

source /etc/profile

5 检查maven版本看是否安装成功

mvn -version 或者mvn -v

ubuntu@ip-172-31-29-46:/opt/apache-maven-3.5.4/conf$ mvn -version
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T18:33:14Z)
Maven home: /opt/apache-maven-3.5.4
Java version: 1.8.0_144, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-48-generic", arch: "amd64", family: "unix"

Linux (Ubuntu)上面安装maven