I just installed node and npm through the package on nodejs.org and whenever I try to search or install something with npm it throws the following error, unless I sudo the c
I encountered this when installing Recess (https://github.com/twitter/recess) to compile my CSS for Bootstrap 3.
When installing recess:
-npm install recess -g
You need to unlock permissions in your home
directory, like Noah
says:
sudo chown -R `whoami` ~/.npm
You also need write permissions to the node_modules
directory, like Xilo
says, so if it still isn't working, try:
sudo chown -R `whoami` /usr/local/lib/node_modules
If you are still seeing errors, you may also need to correct /usr/local permissions:
sudo chown -R `whoami` /usr/local
Please note that as indicated in this post /usr/local/
isn't actually a system dir if you are on a Mac, so, this answer is actually perfectly "safe" for Mac users. However, if you are on Linux, see Christopher Will's answer below for a multi-user friendly, system dir safe (but more complex) solution.