npm安装配置

npm config

  • 配置npmrc
$ NPM_PACKAGES="$HOME/.npm-packages"
$ mkdir -p "$NPM_PACKAGES"

$ echo "prefix = $NPM_PACKAGES" >> ~/.npmrc

$ cat .npmrc
registry=http://r.cnpmjs.org/
prefix = /home/robin/.npm-packages
  • 如果有http代理,需要配置proxy,https-proxy,strict-ssl几个参数。
registry=https://registry.npm.taobao.org
prefix = /home/robin/.npm-packages

proxy=http://proxy_server:ip
https-proxy=http://proxy_server:ip
strict-ssl=false
  • 如果使用Linux,可以通过一下方式自定义安装包路径

cat .bashrc

# NPM packages in homedir
NPM_PACKAGES="$HOME/.npm-packages"

# Tell our environment about user-installed node tools
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 configuration
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"

# Tell Node about these packages
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"

need manually copy ansi package to “$NPM_PACKAGES/lib/node_modules”

升级 nodejs

在ubuntu系统下,默认的nodejs版本过低,导致好些包无法安装。

  • 通过安装n升级nodejs
sudo npm cache clean -f
sudo npm install -g n
sudo n stable

sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/nodejs
  • 通过官方脚本修改nodejs版本
    node v8 (LTS) (For new users: install this one):
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

node v9:

curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install -y nodejs

To update node to latest version just:

sudo apt update
sudo apt upgrade

To keep npm updated

sudo npm i -g npm

镜像源选择nrm

npm i -g nrm
nrm ls
nrm use taobao
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值