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
TL;DR
always use
sudo -iorsudo -Hwhen runningnpm installto install global packages.
When you use npm, it downloads packages to your user home directory. When you run as sudo, npm installs files to the same directory, but now they are owned by root.
So this is what happens to absolutely every single person who has ever used npm:
npm install foosudo install -g foo-cli without issuenpm install barnpm designers now that you have to go chmod a directory againWhen you use the -i or -H option with sudo, your home directory will be root's home directory. Any global installs will cache packages to /root/.npm instead of root-owned files at /home/me/.npm.
Just always use sudo -i or sudo -H when running npm install to install global packages and your npm permissions problems will melt away.
For good.
http://hood.ie/blog/why-you-shouldnt-use-sudo-with-npm.html
--
q.v. the accepted answer for fixing an already messed up npm.