Skip to content

使用版本管理器(多版本切换)

nvm(Node Version Manager)

linux 安装 nvm

bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc  # 重新加载配置
bash
 nvm install 20.16.0   # 安装指定版本
 nvm use 20.16.0     # 切换版本

验证与配置优化

检查版本

bash
node -v  # 应输出类似 v20.16.0
npm -v   # 应输出类似 10.7.0

配置国内镜像加速

bash
npm config set registry https://registry.npmmirror.com