服务器使用 nvm 安装 node
* 安装 nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
或者:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
* 激活 nvm
source ~/.bashrc # 如果是 Bash # 或 source ~/.zshrc # 如果是 Zsh
* 验证是否安装成功
nvm --version
* 使用 nvm 安装 node
nvm install --lts【安装最新版】
nvm install 20.0.0【安装指定版本】
* 查看有哪些版本可以安装
nvm ls-remote【win系统使用:nvm list available】
* 查看已经安装了哪些版本
nvm list
* 切换使用的版本
nvm use 20.0.0 # 临时切换 nvm alias default 20.0.0 # 设为默认版本
* 安装全局 npm 包(可选)
npm install -g yarn
* 如果需要卸载某个版本
nvm uninstall 20.0.0