执行命令安装nvm

sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

修改环境变量

open -e .bash_profile

添加

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

使用

查找已安装node版本

nvm list

安装最新版本

nvm install

查找可用版本

nvm ls-remote

查找lts版本

nvm ls-remote --lts

安装执行版本

nvm install 12.18.3

卸载某个版本

nvm uninstall 8.17.0

设置别名

nvm alias <别名> <版本号>

设置淘宝源

临时配置

npm --registry https://registry.npm.taobao.org install express

永久配置

npm config set registry https://registry.npm.taobao.org