Install npm packages without sudo

Apr 30, 2015 · Updated: Nov 10, 2017 · by Tim Kamanin

If you run the following command to install npm package:

npm install <package_name>

and get an access error, you might be tempted to run this command with sudo and it'll work, but it's not a right way for sure. Npm modules should be installed without sudo. To fix the problem you need to do two things:

1) Set yourself as an owner of ~/.npm directory, like this:

sudo chown -R $(whoami) ~/.npm

and if error persists, set yourself as an owner /usr/local/lib/node_modules directory too, like this:

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

Now you can install npm packages without sudo.

Hey, if you've found this useful, please share the post to help other folks find it:

There's even more:

Subscribe for updates

  • via Twitter: @timonweb
  • old school RSS:
  • or evergreen email ↓ ↓ ↓