【问题标题】:Cannot install bcrypt node.js module on Centos Server无法在 Centos 服务器上安装 bcrypt node.js 模块
【发布时间】:2012-04-26 13:18:45
【问题描述】:

我正在尝试在 CentOS 服务器上安装 bcrypt,但出现以下错误:

info postuninstall bcrypt@0.5.0
ERR! bcrypt@0.5.0 install: `make build`
ERR! `sh "-c" "make build"` failed with 2
ERR!
ERR! Failed at the bcrypt@0.5.0 install script.
ERR! This is most likely a problem with the bcrypt package,
ERR! not with npm itself.
ERR! Tell the author that this fails on your system:
ERR!     make build
ERR! You can get their info via:
ERR!     npm owner ls bcrypt
ERR! There is likely additional logging output above.
ERR!
ERR! System Linux 2.6.18-028stab095.1
ERR! command "nodejs" "/usr/bin/npm" "install" "bcrypt"
ERR! cwd /root/grouplo
ERR! node -v v0.6.15
ERR! npm -v 1.1.16
ERR! code ELIFECYCLE
ERR! message bcrypt@0.5.0 install: `make build`
ERR! message `sh "-c" "make build"` failed with 2
ERR! errno {}

我能做些什么来解决这个问题? 谢谢,

【问题讨论】:

    标签: node.js centos npm bcrypt


    【解决方案1】:

    我在执行 npm install bcrypt 时遇到了同样的问题。 另一种选择是从源代码安装它。

    git clone git://github.com/ncb000gt/node.bcrypt.js.git
    cd node.bcrypt.js
    node-gyp configure
    node-gyp build
    

    将 node.bcrypt.js 文件夹重命名为 bcrypt,并将其移动到项目的 node_modules 中。

    您可以通过执行 npm install -g node-gyp 来安装 node-gyp(-g 全局安装)。

    【讨论】:

    • 我认为我的系统中缺少 openssl。安装后我的问题解决了
    • 对我来说,这在我安装了其他先决条件之前不起作用,这使得 npm install 无论如何都可以正常工作。然而,你肯定给了我一个方向的线索。所以我会投票给你并发布一个替代答案。
    【解决方案2】:

    还有一个不需要编译的原生 js 版本的 bcrypt。 https://github.com/shaneGirish/bcrypt-nodejs

    npm install bcrypt-nodejs
    

    api 与编译后的版本非常相似。以下直接摘自自述文件

    基本用法:

    同步

    var hash = bcrypt.hashSync("bacon");
    
    bcrypt.compareSync("bacon", hash); // true
    bcrypt.compareSync("veggies", hash); // false
    

    异步

    bcrypt.hash("bacon", null, null, function(err, hash) {
        // Store hash in your password DB.
    });
    
    // Load hash from your password DB.
    bcrypt.compare("bacon", hash, function(err, res) {
        // res == true
    });
    bcrypt.compare("veggies", hash, function(err, res) {
        // res = false
    });
    

    【讨论】:

    • bcrypt 令人头疼,我正在迁移到这个。感谢您的选择。
    【解决方案3】:

    对我来说,答案是确保我安装了 gcc、openssl 和 node-gyp。

    要安装 gcc 和 openssl,请使用 yum:

    sudo yum install gcc-c++ openssl-devel
    

    要安装 node-gyp(全局),请使用 npm:

    npm install -g node-gyp
    

    然后 bcrypt 的 npm 安装在 centos 上运行良好

    【讨论】:

      【解决方案4】:

      预构建的二进制文件通常在 bcrypt 新版本发布后的几个小时内或新 NodeJS 版本发布后的几天后可用于 bcrypt。

      但是,请记住,提供二进制文件只是为了方便。

      如果您看到如下错误:

      `在 CentOS / RHEL / Fedora 上您需要以下软件包

      • gcc-c++ - 为了安装编译器链来编译节点模块。
      • make - 通过node-gyp运行生成的Makefile,依次调用编译器
      • python - RHEL 和 CentOS 都安装了所需的 python 版本

      确保使用此命令安装所有依赖项,

      yum install -y gcc-c++ make

      然后继续 bcrypt 安装。

      其他系统见:https://github.com/kelektiv/node.bcrypt.js/wiki/Installation-Instructions

      【讨论】:

        【解决方案5】:

        我也遇到了这个问题,原来我的node和bcrypt不兼容。我使用的是节点版本 lts 12,但我在 package.json 中的 bcrypt 版本是 5,它必须是 3。

        可以查看node和bcrypt不同版本here的兼容性。

        希望对某人有所帮助

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-08-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多