1

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
Reed
  • 287
  • 1
  • 3
  • 10

1 Answers1

2

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.

jorgernan
  • 108
  • 1
  • 5