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

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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

 

以上是关于[Tools] Install npm packages globally without sudo on macOS and Linux的主要内容,如果未能解决你的问题,请参考以下文章

docker image 上的 npm global install 没有访问权限错误

vue的请求数据方式

尝试 npm install web3 时出现致命错误 LNK1181

npm install 和npm install --save 以及npm install --save-dev区别

npm init,npm -y, npm install --save,npm install --save-dev

npm install -save 和npm install -save-dev 给你好看