HomeArticles

Running NPM without sudo

Stefan Baumgartner

Written by @ddprrt

More on 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

More articles on Node.js

Stay up to date!

3-4 updates per month, no tracking, spam-free, hand-crafted. Our newsletter gives you links, updates on fettblog.eu, conference talks, coding soundtracks, and much more.