[Tools] Install npm packages globally without sudo on macOS and Linux

1 . Create a directory for global packages
mkdir "${HOME}/.npm-packages"
2. Tell npm where to store globally installed packages
npm config set 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"

export PATH="$PATH:$NPM_PACKAGES/bin"

# 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"

 

Last:

source ~/.bashrc

 

posted @ 2020-01-27 21:59  Zhentiw  阅读(165)  评论(0编辑  收藏  举报