Why does npm need sudo for EVERYTHING?

macos, node.js, npm, shell

Solution

I encountered the same error after a fresh install of 0.12.4 today; this solved the problem for me:

sudo chown -R $(whoami):admin /usr/local/lib/node_modules

In my particular case, I noticed that this folder was owned by '{some-large-integer-account}:wheel'...YMMV

If that doesn't solve it, take a look at the ownership of the folders that are being blocked as mentioned in the EACCESS error trace. If you're not sure what the ownership should be, you can usually infer it from the sibling dirs' ownership.

Problem

I don't know how I've managed it but npm seems to need `sudo` for absolutely every command, even `npm help` does not work without sudo. If I use a command without `sudo`, I do not see am `EACCESS` error, but instead my terminal session hangs and then just closes that tab (I use iTerm on Mac). I have tried changing the ownership of my local `.npm` folder, outlined here and also done the same on my `/usr/local/bin` folder where node is installed but none of these allow me to just run npm without `sudo`, even when installing local packages...! It seems to me that something has screwed along the way, can anyone help? Many thanks

Original source