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

ar099968 :

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?

j23 :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=28198&siteId=1