Stefan Baumgartner

Web ops, performance and front-end

Running NPM without sudo

08 December 2014 by @ddprrt | Posted in: Node.js

Several ways to fix the problem of running node tools and npm without sudo (which probably always results in an error).

What I do at the moment

Creating npm local in your home directory. Changing the npm configuration and pointing to this directory.

npm config set prefix ~/npm

Adding the directory to my path. Adding this line to .zshrc or .bashrc

export PATH="$PATH:$HOME/npm/bin"

What might also work

Giving the path to all the node directories to the current user:

sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules

Comments? Shoot me a tweet!