CentOS配置Node.js时常见问题及解决方法如下:
“command not found”错误
export PATH=$PATH:/path/to/node/bin
,并重新加载配置(source /etc/profile
)。“Module not found”错误
npm install <模块名>
安装缺失模块,检查代码中模块路径是否正确。端口占用或权限问题
sudo
运行应用,或修改端口为非特权端口(如3000)。GLIBC版本不兼容
“ENOSPC”错误(inotify限制)
/etc/sysctl.conf
,添加 fs.inotify.max_user_watches=524288
,执行 sudo sysctl -p
。依赖冲突或安装失败
npm install --legacy-peer-deps
或 npm audit
检查依赖,确保网络畅通。环境变量配置错误
echo $PATH
检查路径,使用nvm或手动调整环境变量文件(如~/.bashrc
、/etc/profile
)。参考来源: