Home > Net >  Fail to install gatsby-cil : npm ERR! sh: 1: node-gyp-build: Permission denied
Fail to install gatsby-cil : npm ERR! sh: 1: node-gyp-build: Permission denied

Time:03-15

I tried to install gatsby-cil on WLS2 with npm and failed.

here is the error message

root@LAPTOP-7EEFPLOM:~# npm install -g gatsby-cli
npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm ERR! code 127
npm ERR! path /root/.nvm/versions/node/v16.14.0/lib/node_modules/gatsby-cli/node_modules/lmdb
npm ERR! command failed
npm ERR! command sh -c node-gyp-build
npm ERR! sh: 1: node-gyp-build: Permission denied

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-03-14T01_49_08_533Z-debug-0.log

I thought it was WSL that is to blame at first, then I tried to do the same thing on a cloud server and got the same result.

I also tried a solution found on the Internet:

npm config set user 0
npm config set unsafe-perm true

but still got the same error

CodePudding user response:

Try:

sudo chown -R $(whoami) ~/

It seems that you don't have enough permission (in both environments) to install global packages so changing the ~/ permission folder may fix your issue.

Since it's not a Gatsby-related issue (it's from its dependencies), you can also try installing them separately using sudo permissions. In this case:

sudo npm install -g node-gyp node-pre-gyp node-gyp-build

Then you should be able to install gatsby-cli again, which should skip the node-gyp package.

  • Related