I remember I was able to use something like sudo ${which npm} run xxx when I needed root privilege to run npm. What is it?
1 Answer
With bash you can do
sudo "$(which npm)" run ... # or sudo "`which npm`" run ... - yes but it will say node not foundAero Windwalker– Aero Windwalker2020-06-05 07:19:51 +00:00Commented Jun 5, 2020 at 7:19
- @AeroWindwalker By default
sudowill pass thePATHvariable down to the child process, but sudo's security policy can override that. Assumingwhich nodeworks before running sudo, you may need to addDefaults env_keep += "PATH"to your sudoers file (by runningsudo visudo). See here and sudo's man page. If that works you may drop thewhichtrick entirely.joeytwiddle– joeytwiddle2020-06-05 07:46:36 +00:00Commented Jun 5, 2020 at 7:46