It’s possible (and advisable) to npm install -g
node modules without sudo
.
Check the permission of your /usr/local/share/npm/bin
folder. I had installed node and npm through brew (without sudo
) and that particular folder ended up being owned by root.
This fixed it for once and for all:
$ sudo chown $(whoami) /usr/local/share/npm/bin
(As for disallowing sudo
with npm: you’d have to tweak npm for that. Your own node code could make use of https://npmjs.org/package/sudo-block, npm install sudo-block
)
EDIT: even though this works, I no longer use -g
. Instead use prefix (see next answer), or better yet use NIX https://unix.stackexchange.com/a/381797 (even on OSX)