【问题标题】:NodeJS npm install pg failedNodeJS npm install pg 失败
【发布时间】:2013-11-14 07:59:30
【问题描述】:

我试图在我的 ubuntu 虚拟机上 npm install pg 并且出现错误:

> pg@1.1.0 install /usr/local/lib/node_modules/core/node_modules/pg
> node-gyp rebuild || (exit 0)

gyp: binding.gyp not found (cwd: /usr/local/lib/node_modules/core/node_modules/pg) while trying to load binding.gyp
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 
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /root/npm-debug.log
npm ERR! not ok code 0


nodejs -v
v0.10.15
npm -v
1.2.18

知道怎么解决吗?

【问题讨论】:

  • 您的 binding.gyp 不知何故丢失了。您是否尝试重新安装它?
  • 你能告诉我们你的$PATH吗?另外,请参阅此relevant question
  • echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local /游戏
  • sudo apt-get install libpq-dev 帮助 :) 谢谢!

标签: node.js installation npm gyp


【解决方案1】:

尝试先将node-gyp安装到全局范围内?

sudo npm -g install node-gyp

你应该得到一个看起来像这样的结果(在所有 tgz 被拉入之后)

/usr/local/bin/node-gyp -> /usr/local/lib/node_modules/node-gyp/bin/node-gyp.js
node-gyp@0.12.1 /usr/local/lib/node_modules/node-gyp
├── osenv@0.0.3
├── graceful-fs@2.0.1
├── mkdirp@0.3.5
├── which@1.0.5
├── rimraf@2.2.5
├── semver@2.2.1
├── npmlog@0.0.6 (ansi@0.2.1)
├── nopt@2.1.2 (abbrev@1.0.4)
├── glob@3.2.7 (inherits@2.0.1)
├── fstream@0.1.25 (inherits@2.0.1)
├── minimatch@0.2.12 (sigmund@1.0.0, lru-cache@2.5.0)
├── tar@0.1.19 (inherits@2.0.1, block-stream@0.0.7)
└── request@2.29.0 (json-stringify-safe@5.0.0, forever-agent@0.5.0, aws-sign2@0.5.0, qs@0.6.6, tunnel-agent@0.3.0, oauth-sign@0.3.0, node-uuid@1.4.1, mime@1.2.11, tough-cookie@0.9.15, http-signature@0.10.0, hawk@1.0.0, form-data@0.1.2)

【讨论】:

    【解决方案2】:

    我已经安装了 libpq-dev 库

    sudo apt-get install libpq-dev
    

    它有帮助;)

    【讨论】:

    • 这行得通。 OP,请接受此作为他人利益的答案。
    • 请在这个答案中添加一些解释。
    【解决方案3】:

    尝试运行以下命令,然后运行 ​​npm install,这将采用节点的默认 node-gyp 模块。 (不需要有多个,因为节点包已经提供了)

    更新节点和 NPM

    sudo npm cache clean -f
    sudo npm install -g n
    sudo n 4.4.5
    sudo npm install npm -g
    

    移除额外的 Node-gyp 模块

    sudo npm uninstall node-gyp -g
    sudo npm uninstall node-gyp
    

    【讨论】:

    • n是node的别名吗?
    猜你喜欢
    • 2016-01-22
    • 2019-02-23
    • 2017-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-15
    • 1970-01-01
    • 2012-03-03
    相关资源
    最近更新 更多