1.下载地址:
http://maven.apache.org/download.cgi
2 将下载到的apache-maven-3.3.9-bin.tar.gz文件解压移动到/opt目录下,然后切换到root用户下,执行如下命令。
root@test:/下载# tar zxvf apache-maven-3.3.9-bin.tar.gz
root@test:/下载# cd /opt
root@test:/opt# mv /temp/apache-maven-3.3.9 .
3 创建软链接,进入/bin目录下
root@test:/bin# ln -s /opt/apache-maven-3.3.9/bin/mvn mvn
4 添加环境配置
root@test:/~# vim /etc/profile
......
export M2_HOME=/opt/apache-maven-3.3.9
export PATH=${M2_HOME}/bin:$PATH
......
export M2_HOME=/opt/apache-maven-3.3.9
export PATH=${M2_HOME}/bin:$PATH
......
执行下面命令使配置文件生效
root@test:/~# source /etc/profile
当我在执行上述的命令的时候出现了错误,
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-8-oracle-amd64/bin/java
我查了一下,stackflow 上说了两种办法,我是了其中的一种,正确了。
进入/etc/profile 中修改JAVA_HOME的内容:去掉他的后面的bin,直接如下所示。
export JAVA_HOME="/usr/lib/jvm/java-8-oracle"
5 使用其它用户验证
ccskun@test:~$ mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /opt/apache-maven-3.3.9
Java version: 1.8.0_92, vendor: Oracle Corporation
Java home: /opt/jdk1.8.0_92/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-22-generic", arch: "amd64", family: "unix"
ccskun@test:~$
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /opt/apache-maven-3.3.9
Java version: 1.8.0_92, vendor: Oracle Corporation
Java home: /opt/jdk1.8.0_92/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-22-generic", arch: "amd64", family: "unix"
ccskun@test:~$