在 Debian 上安装 Node.js,常见有 3 种方式,步骤数量不同。下面按“最常用、最省事”的方式给你说:
大约 3 步
sudo apt update
sudo apt install -y nodejs npm
node -v
⚠️ 缺点:版本通常偏旧(Debian 稳定版仓库里的 Node 比较老)
大约 4 步
sudo apt update
sudo apt install -y curl
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
node -v
✅ 可装 18 / 20 / 22 等指定版本
大约 5 步
sudo apt install -y curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install --lts
node -v
✅ 适合:前端 / 多版本切换
如果你告诉我 Debian 版本 + 用途(服务器 / 开发),我可以直接给你最合适的一套命令。