3

Following this tutorial

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04

and trying to use the command

echo 'prefix=/usr/local' > node/etc/npmrc

however I get a permission denied error, even when using sudo.

Any ideas?

user2085143
  • 4,162
  • 7
  • 39
  • 68

1 Answers1

10
echo 'prefix=/usr/local' > node/etc/npmrc

however I get a permission denied error, even when using sudo.

You haven't shown us the failing command using sudo. Please update your question and show us the exact command that failed, along with the exact error message.

Meanwhile, I can guess that the failing command was:

sudo echo 'prefix=/usr/local' > node/etc/npmrc

That runs the echo command with root privileges (which is not particularly useful, since you can runecho as an ordinary user). The redirection is handled by your current shell process, and is subject to the permissions of the current user.

Since > is handled by the shell, you need a shell running as root to handle it:

sudo sh -c "echo 'prefix=/usr/local' > node/etc/npmrc"
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631