标签(空格分隔): nvm npm nodejs
nvm (Node Version Manager --- Node版本管理器),用它可以方便的安装并维护多个Node的版本
1 安装 nvm
1.1 执行安装脚本
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
或
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
1.2 设置 nvm 国内镜像
echo "export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node" >> ~/.bashrc
source ~/.bashrc
2 nvm 用法
2.1 查看有哪些 node 版本可以安装
nvm ls-remote
2.2 安装最新版本 node
nvm install stable
2.3 安装指定版本 node
nvm install v7.0.0
2.4 查看已安装 node 版本
nvm ls
-> v8.2.1
default -> 8 (-> v8.2.1)
node -> stable (-> v8.2.1) (default)
stable -> 8.2 (-> v8.2.1) (default)
iojs -> N/A (default)
lts/* -> lts/boron (-> N/A)
lts/argon -> v4.8.4 (-> N/A)
lts/boron -> v6.11.1 (-> N/A)
2.5 显示当前使用的 node 版本
nvm current
2.6 使用指定版本
nvm use 8
2.7 卸载指定版本
nvm uninstall 8
2.8 设置默认版本
nvm alias default 8
2.9 取消默认版本
nvm alias default
3 设置 npm
3.1 安装 cnpm
npm --registry=https://registry.npm.taobao.org install cnpm -g
3.2 设置国内镜像
cnpm 已经默认将 --registry 和 --disturl 都配置好了,但有可能别的程序会调用 npm,所以最好将 npm 也设置一下。
npm config set registry https://registry.npm.taobao.org --global
npm config set disturl https://npm.taobao.org/dist --global
网友评论