什么是NVM
Node.js Version Manager,用来管理 node 的版本。
nodeJS安装
NVM安装
按照官方教程,在命令行执行以下脚本
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
可能遇到的问题:
1、 Failed to connect to raw.githubusercontent.com port 443: Connection refused
前往 /etc/hosts 编辑新增如下:
199.232.28.133 raw.githubusercontent.com
再次执行下载脚本:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
下载成功:
2、 无法找到该命令 command not found
尝试关闭命令行窗口,重新打开
simply close your current terminal, open a new terminal, and try verifying again.
校验nvm安装是否成功
nvm --version
nvm 的常用指令:
nvm install stable
- nvm install stable 安装最新稳定版 node
nvm install
- nvm install 安装指定版本,如:安装v12.19.0,nvm install v12.19.0
nvm uninstall
- nvm uninstall 删除已安装的指定版本,语法与install类似
nvm use
- nvm use 切换使用指定的版本node:如 nvm use v12.19.0
nvm ls
- nvm ls 列出所有安装的版本
nvm alias default
- nvm alias default 如: nvm alias default v14.14.0
NPM 不需要单独安装。默认在安装 Node 的时候,会连带一起安装 NPM。