简体   繁体   中英

Command not found when executed as sudo, but works after "sudo su"

If i try to run this command bash respond with not found error:

$ npm -v
-bash: npm: command not found

with sudo also:

$ sudo npm -v
sudo: npm: command not found

but works when I run first a "sudo su":

$ sudo su
# npm -v
6.10.3

Why this happens? how can I fix it to works with sudo command?

As @franzisk pointed out, this can be issue of the $PATH for the npm.

Try to do echo $PATH both as normal user and super user. Also run which npm as superuser. If you see any difference (for example, path to npm is not in the normal user path) make changes to your PATH variable accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM