Configure NPM for global user without sudo on Mac OS

Using ‘sudo’ with NPM is a no-no, as it can cause all kinds of havoc with file permissions. You can specify a default directory for globally installed packages and thus absolve yourself of sudo chaos.

Create a directory for global packages with

mkdir "${HOME}/.npm-packages"

Tell npm where to store globally installed packages:

npm config set prefix “${HOME}/.npm-packages”

3. Add the following to .bash_profile in your home directory:

# Preserve MANPATH if you already defined it somewhere in your config
# Otherwise, fall back to `manpath` so we can inherit from `/etc/manpath
export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"

Leave a Reply

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