When I put in which npm, I get /usr/local/bin/npm. When I put in command -v npm, I get /usr/bin/npm.

Why is that? What's the difference? man which says which "returns the pathnames of the filenames that would be executed in the current environment". I see that if I run which -a npm, it returns both of the paths mentioned above.

So why does it pick the first one when run without -a, while command -v npm returns the second one?


which is an external command from the csh times that is not related to Bourne compatible shells.

As a result, it may return wrong results unless you use csh.

So better use built in shell commands...

command is a built in command from POSIX compatible shells and together with the other builtin type returns the right results for shells that are similar to the Bourne Shell.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.