在 CentOS 上,Node.js 的“配置”通常指以下几类,位置和方法不同,我按常见情况说明:
一般通过以下方式安装:
which node
常见路径:
/usr/bin/node
配置文件位置:
/etc/profile、/etc/bashrcnvm which node
路径类似:
~/.nvm/versions/node/v18.x.x/bin/node
nvm 配置:
~/.nvm/settings.txt
路径例如:
/opt/nodejs/bin/node
配置通过:
/etc/profile.d/node.sh
npm config set registry https://registry.npmmirror.com
配置文件位置:
~/.npmrc
npm config set prefix /usr/local/node_global
查看:
npm config get prefix
服务文件:
/etc/systemd/system/node.service
示例:
[Unit]
Description=Node App
After=network.target
[Service]
ExecStart=/usr/bin/node /opt/app/index.js
User=node
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
操作:
systemctl daemon-reload
systemctl start node
systemctl enable node
编辑:
/etc/profile.d/node.sh
内容示例:
export NODE_HOME=/opt/nodejs
export PATH=$NODE_HOME/bin:$PATH
node -v
npm -v
which node
npm config list
如果你是指 “Node.js 的某个错误配置 / 端口 / 权限 / 开机启动”,可以告诉我具体场景,我可以给你更精确的配置文件路径。