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
)。參考來源: