-2

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 1

0

With bash you can do

sudo "$(which npm)" run ... # or sudo "`which npm`" run ... 
2
  • yes but it will say node not found Commented Jun 5, 2020 at 7:19
  • @AeroWindwalker By default sudo will pass the PATH variable down to the child process, but sudo's security policy can override that. Assuming which node works before running sudo, you may need to add Defaults env_keep += "PATH" to your sudoers file (by running sudo visudo). See here and sudo's man page. If that works you may drop the which trick entirely. Commented Jun 5, 2020 at 7:46

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.