花了3+个小时解决的问题,记录一下。
我在 Ubuntu 18.04 上安装 npm install pg 时,出现错误:
......
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/share/node-gyp/lib/configure.js:431:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Linux 3.11.0-12-generic
gyp ERR! command "nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/core/node_modules/pg
gyp ERR! node -v v0.10.15
gyp ERR! node-gyp -v v0.10.9
gyp ERR! not ok
......
在网上搜索,试了几种方式都不成功。有一个答案说要安装 libpg-dev:
sudo apt-get install libpq-dev
结果安装这个库又报错:
libpq-dev : Depends: libpq5 (= 8.4.17-0squeeze1) but 9.1.9-1~bpo60+1 is to be installed
又经过一番实验和搜索,终于解决了。解决过程如下:
安装特定版本:
sudo apt install libpq5=10.12-0ubuntu0.18.04.1
sudo apt-get install libpq-dev