I need to run node on my Ubuntu machine with sudo access. The directory of node is in the sudo path but when trying to run it i get a command not found. I can explicitly call node which does work.
//works
node
>
which node
/root/local/node/bin/node
echo sudo $PATH
sudo /root/local/node/bin:/usr/bin/node:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
sudo node --version
sudo: node: command not found
//explicitly calling it works
sudo node /root/local/node/bin
>
Um, I don’t think there’s such a thing as a “sudo path” – your second command there is just echoing “sudo” followed by your regular path. In any case, if you’re running things with
sudoyou really, really should not depend on a path – you should give the explicit pathname for every command and file argument whenever possible, to minimize security risks. Ifsudodoesn’t want to run something, you need to usevisudoto add it to/etc/sudoers.