8

I'm trying to install bcrypt on CentOS server but I got the following error:

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 {}

What Can I do to solve this? Thanks,

Feras Odeh
  • 9,136
  • 20
  • 77
  • 121

5 Answers5

14

There is also a native-js version of bcrypt which does not require compiling. https://github.com/shaneGirish/bcrypt-nodejs

npm install bcrypt-nodejs

The api is very similar to the compiled version. The following is taken directly from the readme

Basic usage:

Synchronous

var hash = bcrypt.hashSync("bacon");

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

Asynchronous

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
});
Noah
  • 33,851
  • 5
  • 37
  • 32
7

For me the answer was to ensure that I had gcc, openssl and node-gyp installed.

To install gcc and openssl, use yum:

sudo yum install gcc-c++ openssl-devel

To install node-gyp (globally), use npm:

npm install -g node-gyp

Then the npm install of bcrypt worked just fine on centos

iandotkelly
  • 9,024
  • 8
  • 48
  • 67
5

I got the same issue doing npm install bcrypt. The other option is to install it from source.

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

Rename the node.bcrypt.js folder to bcrypt, and move it into your node_modules of your project.

You can install node-gyp by doing npm install -g node-gyp (-g installs it globally).

gruuuvy
  • 2,028
  • 4
  • 31
  • 52
  • 2
    I think openssl was missing in my system. After installing my problem solved – Feras Odeh Jun 10 '12 at 06:12
  • 1
    For me this didn't work until I'd installed other pre-requisites which enabled npm install to work just fine anyway. However you certainly gave me a clue in which direction to go. So I'll upvote you and post an alternative answer. – iandotkelly Jan 03 '14 at 02:37
2

Pre-built binaries are usually available for bcrypt in a few hours after a new release of bcrypt or after a few days after a new NodeJS version is released.

However, remember that binaries are only provided as a convenience.

If you see an error such as:

`You need the following packages on CentOS / RHEL / Fedora

  • gcc-c++ - In order to install a compiler chain to compile the node modules.
  • make - To run the generated Makefile by node-gyp, which invokes compilers in order
  • python - RHEL and CentOS come with the required version of python installed

Make sure all dependencies are installed with this command,

yum install -y gcc-c++ make

and then proceed with the bcrypt installation.

For other systems see: https://github.com/kelektiv/node.bcrypt.js/wiki/Installation-Instructions

recrsn
  • 450
  • 5
  • 12
0

I also had this problem, it turned out that my node wasn't compatible with bcrypt. I was using node version lts 12 but my bcrypt version in package.json was 5, which must be 3.

You can check the compatibility of node and bcrypt different versions here.

Hope it helped someone

MajidJafari
  • 1,076
  • 11
  • 15