error - node-gyp-build: Permission denied while setting up truffle and ganache with docker on Apple Silicon
npm ERR! code 127
npm ERR! path /root/.nvm/versions/node/v17.9.0/lib/node_modules/truffle/node_modules/leveldown
npm ERR! command failed
npm ERR! command sh -c node-gyp-build
npm ERR! sh: 1: node-gyp-build: Permission denied
These are some steps i followed to install truffle with docker on my m1 Macbook. I'll be doing it for ubuntu image container
on your container execute below:
Then install nvm from https://github.com/nvm-sh/nvm#install--update-script
On above link there must be these two commands but with updated versions
then install node and npm with:
after executing
you'll find a statement to update npm to the latest version, execute that command, which should look like,
npm install -g [email protected]
, after that install trufflethere will be a permission issue in executing above command for which you've to execute
Note: the above command has path to
node_modules
you need to find the path to your node_modules from your error. in my case it was/root/.nvm/versions/node/v17.9.0/lib/node_modules/
so i executed,sudo chown -R $(whoami) /root/.nvm/versions/node/v17.9.0/lib/node_modules/
retry
npm install -g truffle
after this you should be done with installation, but you would face problems where you couldn't execute the truffle file. for this just allow your truffle file to be executed by running:
chmod u+x <path to truffle>
you may find the path to truffle with which truffle, execute as below.chmod u+x /root/.nvm/versions/node/v17.9.0/bin/truffle
For Ganache installation:
To your package.json add,
Then execute,
you should be able to see output something like
RPC Listening on 127.0.0.1:8545
now execute truffle console, make sure you add correct port number like above
8545
in filetruffle-config.js
of your code, when you use it.now execute
truffle console