Ubuntu 14.04
安装后通过`update-alternatives`更改版本后mvn
,配置保持不变。
脚步
安装新版本 mvn
sudo update-alternatives --install /usr/bin/mvn mvn /opt/maven/apache-maven-3.5.0/bin/mvn 100
检查替代方案
$ sudo update-alternatives --config mvn There are 2 choices for the alternative mvn (providing /usr/bin/mvn). Selection Path Priority Status ------------------------------------------------------------ * 0 /opt/maven/apache-maven-3.3.9/bin/mvn 100 auto mode 1 /opt/maven/apache-maven-3.3.9/bin/mvn 100 manual mode 2 /opt/maven/apache-maven-3.5.0/bin/mvn 10 manual mode Press enter to keep the current choice[*], or type selection number: 2 update-alternatives: using /opt/maven/apache-maven-3.5.0/bin/mvn to provide /usr/bin/mvn (mvn) in manual mode
将替代方案更改为新方案
$ sudo update-alternatives --config mvn There are 2 choices for the alternative mvn (providing /usr/bin/mvn). Selection Path Priority Status ------------------------------------------------------------ 0 /opt/maven/apache-maven-3.3.9/bin/mvn 100 auto mode 1 /opt/maven/apache-maven-3.3.9/bin/mvn 100 manual mode * 2 /opt/maven/apache-maven-3.5.0/bin/mvn 10 manual mode Press enter to keep the current choice[*], or type selection number: 2
检查 mvn 版本
$ mvn --version Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T17:41:47+01:00) Maven home: /opt/maven/apache-maven-3.3.9 Java version: 1.8.0_111, vendor: Oracle Corporation Java home: /opt/java/jdk1.8.0_111/jre Default locale: ca_ES, platform encoding: UTF-8 OS name: "linux", version: "3.13.0-116-generic", arch: "amd64", family: "unix"
type
命令输出:
$ type -a mvn
mvn is /opt/maven/apache-maven-3.3.9/bin/mvn
mvn is /usr/bin/mvn
答案1
我已经修改了~/.profile
PATH
变量,所以我唯一要做的就是注释掉该行并再次登录。
。轮廓
...
#export PATH=/opt/maven/apache-maven-3.3.9/bin:$PATH
...
答案2
包括手册页和调试命令中的替代方案,只需添加奴隶像这样的选项:
INSTALL_HOME="/opt/maven/apache-maven-3.5.0"
sudo update-alternatives --install "/usr/bin/mvn" "mvn" "${INSTALL_HOME}/bin/mvn" 100 \
--slave "/usr/bin/mvnDebug" "mvnDebug" "${INSTALL_HOME}/bin/mvnDebug" \
--slave "/usr/share/man/man1/mvn.1.gz" "mvn.1.gz" "${INSTALL_HOME}/man/mvn.1.gz" \
--slave "/usr/share/man/man1/mvnDebug.1.gz" "mvnDebug.1.gz" "${INSTALL_HOME}/man/mvnDebug.1.gz"
暗示:如果你的下载不包含手册页,你可以使用帮助2人生成mvn.1.gz
然后符号链接mvnDebug.1.gz
到它。
cd ${INSTALL_HOME}/man
ln -s mvn.1.gz mvnDebug.1.gz