Fixing npm global install permissions on MacOS

By default npm on MacOS tries to install global modules (npm install -g somemodule) to /usr/local/lib/node_modules and you get this error:

Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'

The npm docs here have a couple of steps to avoid this by telling npm to install to a location where you have have access to:

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'

Edit your .profile or .bash_profile to add the new location to your PATH:

export PATH=~/.npm-global/bin:$PATH

Now you should be all set!




2 Replies to “Fixing npm global install permissions on MacOS”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.