node.bcrypt.js: `npm install bcrypt` fails in install: `node-gyp rebuild`

Hello,

I’m trying to install bcrypt on my debian machine and it fails with the below error. Can you please let me know what am I missing.

Thanks Jothiram.

root@debian:/home/node# npm install -g bcrypt npm http GET https://registry.npmjs.org/bcrypt npm http 304 https://registry.npmjs.org/bcrypt npm http GET https://registry.npmjs.org/bindings/1.0.0 npm http 304 https://registry.npmjs.org/bindings/1.0.0

bcrypt@0.7.0 install /usr/local/lib/node_modules/bcrypt node-gyp rebuild

info it worked if it ends with ok ERR! Error: EACCES, stat ‘/root/.node-gyp/0.6.18’ ERR! not ok

npm ERR! bcrypt@0.7.0 install: node-gyp rebuild npm ERR! sh "-c" "node-gyp rebuild" failed with 1 npm ERR! npm ERR! Failed at the bcrypt@0.7.0 install script. npm ERR! This is most likely a problem with the bcrypt package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! node-gyp rebuild npm ERR! You can get their info via: npm ERR! npm owner ls bcrypt npm ERR! There is likely additional logging output above. npm ERR! npm ERR! System Linux 2.6.32-5-686 npm ERR! command “node” “/usr/local/bin/npm” “install” “-g” “bcrypt” npm ERR! cwd /home/node npm ERR! node -v v0.6.18 npm ERR! npm -v 1.1.21 npm ERR! code ELIFECYCLE npm ERR! message bcrypt@0.7.0 install: node-gyp rebuild npm ERR! message sh "-c" "node-gyp rebuild" failed with 1 npm ERR! errno {} npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /home/node/npm-debug.log npm not ok

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Reactions: 2
  • Comments: 59 (4 by maintainers)

Most upvoted comments

Ah no, here’s the fix: sudo apt-get install build-essential

I find astonishing 4 years later this hasn’t been fixed yet.

I experience this issue every few weeks - I think it has to do with node version changes (which I do using n) and also general upgrades. Just doing npm i -g node-gyp && node-gyp clean did not do the trick but the following did. Basically update my bcrypt to the very latest, uninstall node-gyp and reinstall. Some of the steps may be unnecessary but it worked.

npm un bcrypt;npm i bcrypt --save;npm un node-gyp -g;npm i -g node-gyp && node-gyp clean

I had the exact same issue when running tests on Travis CI. The issue was resolved for node 0.10.x after I ran updated node-gyp and cleaned before building (using npm i -g node-gyp && node-gyp clean).

The easiest way to make sure this runs on every install of bcrypt (or other packages which have similar issues, like node-toobusy) is to add it to your package.json, in the scripts element:

...
"scripts": {
  "preinstall": "npm i -g node-gyp && node-gyp clean"
}
...

I’m not sure if it is a global fix for the problem, but it worked for me, so I figured I’d share my findings 😉

@louischatriot Try updating npm and trying again (npm install -g npm usually).

All I did was “sudo npm install bcrypt --save” It just needs admin permissions 😃

@codersbrothers your comment is not helpful in the slightest. Please refrain from doing such dumps on issues as it is both annoying and does not relate to this issue.

yes this doesn’t seem to be a nodejitsu only issue

I recently had that issue on AMAZON LINUX EC2 Instance and to fix it:

npm install -g npm sudo yum groupinstall "Development tools" npm install bcrypt --save

In my case I was able to install bcrypt (which at the time of writing is (0.8.7), but I cannot install older versions, the node-nyp will vail.

I was abel to make some progress by adding the following variable SET VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120

Note that on 32bit system the (x86) is not there.

Update

When using meteor adding bcrypt by meteor add npm-bcrypt works like a sharm.

@Kagiso25 looks like you don’t have g++ installed…

To get it to work on nodejitsu:

In your package.json, in the env section add a python variable that points to /opt/local/bin/python2.7

A sample package.json:

    {
        "name":"bcrypt-test",
        "version":"0.1",
        "dependencies":{
            "bcrypt":"*"
        },
        "env": {
              "PYTHON": "/opt/local/bin/python2.7"
        },
        "subdomain":"bcrypt-test",
        "engines":{
              "node":"0.6.x"
        },
        "repository": {},
        "domains": [],
        "databases": {}
    }

After searching Google for an hour I did the following 3 things and it began to work after the very last one.

1.) I made sure Python was downloaded to C:\Python2.7 and the path variable for Python was set. 2.) I did
npm install --global --production windows-build-tools

3.) I added the below to my package.json as shown on another github thread. After doing this, and making sure the PYTHON variable was right it started to work.

 "env": {
    "PYTHON": "C:/python2.7"
  },
  "subdomain": "bcrypt-test",
  "engines": {
    "node": "0.6.x"
  },
  "repository": {},
  "domains": [],
  "databases": {}
}

Thanks man, @RichardJECooke - made my day.

@AvianFlu from Nodejitsu pointed me to: http://wiki.smartos.org/display/DOC/Building+node.js+Binary+Addons+on+SmartMachines

I then tried the following:

CC=/opt/local/bin/gcc CXX=/opt/local/bin/gcc npm install bcrypt  

which was successful:

[node@x ~]$ CC=/opt/local/bin/gcc CXX=/opt/local/bin/gcc npm install bcrypt          
npm http GET https://registry.npmjs.org/bcrypt
npm http 304 https://registry.npmjs.org/bcrypt
npm http GET https://registry.npmjs.org/bcrypt/0.7.0
npm http 304 https://registry.npmjs.org/bcrypt/0.7.0

> bcrypt@0.7.0 install /home/node/local/lib/node_modules/bcrypt
> node-gyp rebuild

make: Entering directory `/home/node/local/lib/node_modules/bcrypt/build'
  CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o
  CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt.o
  CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt_node.o
  SOLINK_MODULE(target) Release/obj.target/bcrypt_lib.node
  SOLINK_MODULE(target) Release/obj.target/bcrypt_lib.node: Finished
  COPY Release/bcrypt_lib.node
make: Leaving directory `/home/node/local/lib/node_modules/bcrypt/build'
bcrypt@0.7.0 local/lib/node_modules/bcrypt

> bcrypt@0.7.0 install /home/node/node_modules/bcrypt
> node-gyp rebuild

make: Entering directory `/home/node/local/lib/node_modules/bcrypt/build'
  CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o
  CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt.o
  CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt_node.o
  SOLINK_MODULE(target) Release/obj.target/bcrypt_lib.node
  SOLINK_MODULE(target) Release/obj.target/bcrypt_lib.node: Finished
  COPY Release/bcrypt_lib.node
make: Leaving directory `/home/node/local/lib/node_modules/bcrypt/build'
/home/node/node_modules/bcrypt -> /home/node/local/lib/node_modules/bcrypt
bcrypt@0.7.0 node_modules/bcrypt

@ncb000gt @TooTallNate in fact, the issue was that the ~/.node-gyp folder was owned by the root user so any normal user wasn’t able to create a folder in it. Deleting it enabled node-gyp to recreate it with the proper owner and prvileges.

That said, updating npm with node couldn’t have been a bad idea 😃 Thanks for you help.