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