node.bcrypt.js: node-gyp: Permission denied

I can’t install the latest, 0.7.5, on my ubuntu server. This is giving me strong deja vu. I think I’ve seen this on other modules and maybe on bcrypt before. I don’t remember how I got past it. Maybe the problem has to do with installing while logged in as root? Here is the error:

$ 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/bindings/1.0.0
npm http 304 https://registry.npmjs.org/bindings/1.0.0

> bcrypt@0.7.5 install /ri/node_modules/bcrypt
> node-gyp rebuild

sh: 1: node-gyp: Permission denied
npm ERR! bcrypt@0.7.5 install: `node-gyp rebuild`
npm ERR! `sh "-c" "node-gyp rebuild"` failed with 127
npm ERR!
npm ERR! Failed at the bcrypt@0.7.5 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! System Linux 3.2.0-31-virtual
npm ERR! command "/root/.nvm/v0.10.0/bin/node" "/root/.nvm/v0.10.0/bin/npm" "install" "bcrypt"
npm ERR! cwd /ri
npm ERR! node -v v0.10.0
npm ERR! npm -v 1.2.14
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /ri/npm-debug.log
npm ERR! not ok code 0

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 15 (2 by maintainers)

Most upvoted comments

You have permission problems. Fix them.

npm install --unsafe-perm

So, after a little digging on the tubes I came across https://github.com/isaacs/npm/issues/294.

I’m guessing that you’ll need to use npm install bcrypt --unsafe-perms

Hi all, following this commend working fine…😃 #npm install -g node-gyp node-pre-gyp or $sudo npm install -g node-gyp node-pre-gyp

BTW, I put the prompt $ in my sample output but I just did that to remove the long prompt that was there. I’m always logged in as root. I do sudo -i every time I start a session. I’ve used unix/linux on and off for 35 years (not a typo) and I’ve never logged in as anything but root. I know it is supposed to be dangerous but I’ve never understood why. I’ve never typed rm -rf / and I don’t plan to.

Adding a non-root user and installing node there helped me.

This is quite dummy solution, but in my case, after trying all of your suggestions out, only deleting node v8.4.0 and installing v9.2.0 (all done as non-root) helped. I have to admit, that I have no clue about the reason of this issue.