在 Debian 上安装 Node.js,通常 3~5 步就能完成,取决于你用哪种方式。下面给你几种常见方案,按“步骤数”从少到多说:
适合:只是想用 Node,不追求最新版
sudo apt update
sudo apt install -y nodejs npm
node -v
✅ 完成
⚠️ 版本一般偏旧(比如 18.x 或更早)
适合:想要较新稳定版(如 20 / 22)
sudo apt update
sudo apt install -y curl
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install -y nodejs
验证:
node -v
npm -v
适合:多版本切换、前端/后端开发
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
✅ 可随时 nvm use 20
如果你告诉我:
我可以直接给你一条最合适的具体命令。