大网数据广告活动
服务器运维问答

nodejs overwritten /usr/bin/which, how to fix?

· 52CE 我爱测

I have a newly installed centos 7 with only some nodejs projects. Then I found which command is not working properly. # which ls which: illegal option -- - usage: which [-as] program ... # echo $PATH /usr/local/sbin:/usr/local/bi…

问题原文

原帖链接 · Reed · CC BY-SA 3.0

I have a newly installed centos 7 with only some nodejs projects. Then I found which command is not working properly.

# which ls
which: illegal option -- -
usage: which [-as] program ...

# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

but this works:

# /usr/bin/which ls
/usr/bin/ls

Then I did a cat /usr/bin/which, found it has been replaced by a nodejs program!

#!/usr/bin/env node
var which = require("../")
if (process.argv.length < 3)
  usage()

function usage () {
  console.error('usage: which [-as] program ...')
  process.exit(1)
}
... ...

which command is a node program

# ls -la /usr/bin/which
lrwxrwxrwx 1 root root 63 Jul  5 20:43 /usr/bin/which -> ../local/share/.config/yarn/global/node_modules/which/bin/which

I am confused as hell, why the hell would nodejs replace a perfectly working system command?

Now the question is, what is the correct way to fix it? Can I just delete the file and copy which from another computer(vm)?

update:

Here is how I installed nodejs and yarn. Other modules was installed in project dir.

curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum install nodejs

sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
yum install yarn

yarn global add nuxt
yarn global add cross-env
npm install pm2 -g

已采纳解答

原帖链接 · jorgernan · CC BY-SA 3.0

I have the same problem when installed yarn in Fedora.

I realize that command which, calling without using absolute path, in reality is an alias.

# alias which
alias which='(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot'

Using the following rpm command in Fedora, I could also confirm /usr/bin/which soft link was replaced.

# rpm -V which
....L....    /usr/bin/which

I solved the problem reinstalling which package.

sudo yum reinstall which

I do not think it is correct nodejs should replace an important system program so a guest it was a issue in nodejs developer team.

PS: Sorry for my English.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-07-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。