This question already has an answer here:
- command not found when using sudo 6 answers
I have a problem.
Lately I've installed
nodejs (if you don't know what it is, it does not really matter, could be anything else) from sources to /opt/node:
$ ls -la /opt ... lrwxrwxrwx 1 root root 11 2012-07-25 13:48 node -> node-0.6.3/ drwxr-xr-x 6 root root 4096 2012-07-25 13:48 node-0.6.3 ...
so, the binaries are in
$ ls -la /opt/node/bin ... lrwxrwxrwx 1 root root 38 2012-06-20 11:44 npm -> ../lib/node_modules/npm/bin/npm-cli.js ...
As you can see,
npm is there.
To make it easier to use it from a command line I fixed
and so did to the root's
# which npm /opt/node/bin/npm
But if I run npm with sudo,
npm is not found:
$ sudo which npm $ sudo npm -g install uglify-js sudo: npm: command not found
So, why is it happening? How do I gain what I want?
UPDATE: Following Paul's advice, I've added
Defaults env_keep = PATH
but the problem persists anyway:
$ echo $PATH ... :/opt/node/bin $ sudo su - # # sudo -V ... Environment variables to preserve: XAUTHORIZATION XAUTHORITY TZ PS2 PS1 PATH ...
Defaults directive did it's job, but I'm getting the same
sudo: npm: command not found