下面给你一份面向新手的 CentOS 配置 Node.js 教程,步骤尽量简单、可复制。
sudo yum update -y
sudo yum install -y curl
curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
想用其他版本,把
18.x改成20.x等
sudo yum install -y nodejs
node -v
npm -v
能看到版本号就说明成功 ✅
mkdir test && cd test
新建文件:
vi app.js
输入:
console.log("Hello Node.js");
运行:
node app.js
sudo npm install -g nrm
或换国内镜像(推荐):
npm config set registry https://registry.npmmirror.com
说明系统太老(如 CentOS 6),建议:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install 18
如果你是 CentOS 7 / 8 / Stream,或者想装 特定版本 / 配 PM2 / Nginx,告诉我,我可以一步步带你配。