Skip to content

Instantly share code, notes, and snippets.

@matinrco
Last active March 9, 2018 17:25
Show Gist options
  • Save matinrco/d3c7311ce32e59a5e2dc4596c8178961 to your computer and use it in GitHub Desktop.
Save matinrco/d3c7311ce32e59a5e2dc4596c8178961 to your computer and use it in GitHub Desktop.
Install npm packages globally without sudo on macOS or Linux

Install npm packages globally without sudo on macOS or Linux

1. Create a directory for global packages
mkdir "${HOME}/.npm-packages"
2. Indicate to npm where to store globally installed packages. In your ~/.npmrc file add:
prefix=${HOME}/.npm-packages
3. Ensure npm will find installed binaries and man pages. Add the following to your .bashrc/.zshrc:
NPM_PACKAGES="${HOME}/.npm-packages"

PATH="$NPM_PACKAGES/bin:$PATH"

# Unset manpath so we can inherit from /etc/manpath via the `manpath` command
unset MANPATH # delete if you already modified MANPATH elsewhere in your config
export MANPATH="$NPM_PACKAGES/share/man:$(manpath)"

Summarized from here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment