主题
Linux 平台
在 Linux 上安装 Node.js 运行环境。以下命令适用于 Ubuntu / Debian,其它发行版请做相应替换。
方法一:NodeSource 官方脚本
bash
# Node.js 20.x
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
# 验证
node -v
npm -v方法二:nvm(推荐)
bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
source ~/.bashrc
nvm install 20
nvm use 20
nvm alias default 20CentOS / RHEL / Rocky
bash
curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -
sudo yum install -y nodejsAlpine(Docker 场景常见)
bash
apk add --no-cache nodejs npm换源
bash
npm config set registry https://registry.npmmirror.com