Linux 下修改 npm 全局安装目录为用户目录

出于许多原因,需要修改 npm 全局安装目录 “/usr/lib/node_module” 为 “~/.npm-global” 。

建立目录:

mkdir ~/.npm-global

配置 npm 目录:

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

配置环境变量,在 ~/.bash_profile 或 ~/.profile 中添加:

export PATH="$HOME/.npm-global/bin:$PATH"

重新加载 bash profile:

source ~/.profile

参考:

  1. https://docs.npmjs.com/getting-started/fixing-npm-permissions

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

You are commenting using your WordPress.com account. Log Out /  更改 )

Google photo

You are commenting using your Google account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

Connecting to %s