码迷,mamicode.com
首页 > 其他好文 > 详细

-bash: /usr/bin/mvn: Too many levels of symbolic links

时间:2017-12-08 23:08:24      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:相对路径   问题   style   -bash   for   div   cal   odi   default   

问题背景:

root 用户安装了maven,切换到jenkins 用户可以正常执行mvn 命令,但是jenkins job 构建任务却无法执行mvn命令,报错如下:/bin/sh: 1: mvn: not found

1、root用户安装maven

root# mvn -v
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T07:58:13Z)
Maven home: /usr/share/maven
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/java/jdk1.8.0_151/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-135-generic", arch: "amd64", family: "unix"

2、root用户配置/etc/profile 文件,并source 使配置生效

export M2_HOME=/usr/share/maven
export PATH=$PATH:${M2_HOME}/bin 

3、切换到ubuntu用户执行mvn命令,报错

ubuntu@$ whereis mvn
mvn: /usr/bin/mvn /usr/bin/X11/mvn /usr/share/man/man1/mvn.1.gz
ubuntu@$ /usr/bin/mvn -v
-bash: /usr/bin/mvn: Too many levels of symbolic links

4、root用户下查看/usr/bin/mvn 软连接信息

root@# whereis mvn
mvn: /usr/bin/mvn /usr/bin/X11/mvn /usr/share/man/man1/mvn.1.gz
root@# ll
/usr/bin/mvn lrwxrwxrwx 1 root root 3 Dec 8 13:44 /usr/bin/mvn -> mvn

5、更改软连接方式

root@# rm -f /usr/bin/mvn
root@# ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
root@# ll /usr/bin/mvn
lrwxrwxrwx 1 root root 24 Dec  8 13:47 /usr/bin/mvn -> /usr/share/maven/bin/mvn*

6、ubuntu用户下再次验证

ubuntu@$ mvn -v
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T07:58:13Z)
Maven home: /usr/share/maven
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/java/jdk1.8.0_151/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-135-generic", arch: "amd64", family: "unix"

 

总结:

建立软连接的时候,尽量采用绝对路径,避免采用相对路径建立软链接。

-bash: /usr/bin/mvn: Too many levels of symbolic links

标签:相对路径   问题   style   -bash   for   div   cal   odi   default   

原文地址:http://www.cnblogs.com/songfucai/p/8007277.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!