参考
Linux安装Node.js
- 安装Git
- 获取NVM源码
1
git clone https://gitee.com/mirrors/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
- 配置NVM环境变量
1
2sudo sh -c 'echo ". ~/.nvm/nvm.sh" >> /etc/profile'
source /etc/profile - 配置npm镜像源为阿里云镜像
1
npm config set registry http://registry.npmmirror.com
Windows 安装nvm
- GitHub下载nvm
- 安装nvm,安装时设置nvm安装路径和nodejs安装路径,会自动添加
NVM_HOME和NVM_SYMLINK系统变量(不是管理员运行可能添加失败)。
NVM使用
nvm install <version> [arch]:<version>:可以是具体版本号、”latest”(最新稳定版)或 “lts”(最新长期支持版)。
nvm use <version>:切换到指定版本的Node.js环境。nvm npm_mirror [url]: 设置 npm 镜像源,默认为 https://github.com/npm/cli/archive/。留空 [url] 使用默认地址。
指定 NPM 镜像仓库
- 命令全局设置 NPM 镜像
npm config set registry <镜像地址> - 查看当前仓库 npm config get registry