在 Debian 上运行 Node.js 一般有几种常见方式,下面按推荐程度给你说明。
Debian 自带仓库里的 Node 通常比较旧,建议用 NodeSource。
sudo apt update
sudo apt upgrade -y
sudo apt install -y curl gnupg
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
想装 18:
setup_18.x
想装 22:setup_22.x
sudo apt install -y nodejs
node -v
npm -v
sudo apt update
sudo apt install -y nodejs npm
适合:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install 20
nvm use 20
优点:
nano hello.js
内容:
console.log("Hello Debian Node.js");
node hello.js
node app.js &
或用:
pm2systemddocker如果你愿意,我可以帮你:
你现在是 桌面 Debian 还是服务器?用来做什么?