如何在 Apple Silicon 上使用 Docker 设置 Truffle 和 Ganache
错误 - 节点gyp-build:在用Apple Silicon上使用Docker设置松露和Ganache时拒绝了许可
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是我在 m1 Macbook 上使用 docker 安装 truffle 时遵循的一些步骤。
我将为
容器上的 ubuntu 映像容器执行此操作,执行如下:
然后从 https://github.com/nvm-sh/nvm#install--update-script
在上面的链接上必须有这两个命令,但使用更新版本
然后安装节点和 npm:
后
执行 会找到更新 npm 的语句到最新版本,执行该命令,该命令应类似于
npm install -g [email protected]
,安装truffle后,执行上述命令时会出现权限问题,您必须执行
注意:上面的命令有
node_modules
的路径,您需要从错误中找到node_modules的路径。就我而言,它是 /root/.nvm/versions/node/v17.9.0/lib/node_modules/ 所以我执行了,sudo chown -R $(whoami) /root/.nvm /versions/node/v17.9.0/lib/node_modules/
重试
npm install -g truffle
在此之后您应该完成安装,但是您会遇到无法执行 truffle 文件的问题。
为此,只需运行以下命令即可执行您的松露文件:
chmod u+x
你可以用哪个truffle找到truffle的路径,执行如下。chmod u+x /root/.nvm/versions/node/v17.9.0/bin/truffle
对于 Ganache 安装:
到你的 package.json 添加,
然后执行,
你应该能够看到输出一些东西就像
RPC Listening on 127.0.0.1:8545
现在执行 truffle 控制台一样,请确保在文件中添加正确的端口号,如上面的
8545
当您使用代码时,您的代码的truffle-config.js
。现在执行
truffle console
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