在 CentOS 上选择 Node.js 版本,主要看你的 CentOS 版本 和 使用场景。下面给你一个简明建议:
curl -fsSL https://rpm.nodesource.com/setup_18.x | bash -
yum install -y nodejs
dnf module list nodejs
dnf module enable nodejs:20
dnf install nodejs
| 场景 | 推荐版本 |
|---|---|
| 生产环境 | LTS(18 / 20) |
| 学习 / 测试 | 最新 LTS |
| 老项目 | 跟随项目要求(如 14 / 16) |
| 新项目 | Node 20 LTS |
⚠️ 不建议使用 非 LTS(如 odd 版本 21、23) 用于生产
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
nvm install 20
nvm use 20
curl -fsSL https://rpm.nodesource.com/setup_20.x | bash -
yum install -y nodejs
如果你告诉我:
我可以直接给你最合适的具体版本和安装命令。