如何在 Apple Silicon 上使用 Docker 设置 Truffle 和 Ganache

发布于 2025-01-20 13:13:21 字数 316 浏览 3 评论 0原文

错误 - 节点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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑看君怀她人 2025-01-27 13:13:21

以下是我在 m1 Macbook 上使用 docker 安装 truffle 时遵循的一些步骤。
我将为

docker run -it ubuntu

容器上的 ubuntu 映像容器执行此操作,执行如下:

apt-get update && apt-get upgrade 
apt-get install sudo build-essential python3 wget curl

然后从 https://github.com/nvm-sh/nvm#install--update-script

在上面的链接上必须有这两个命令,但使用更新版本

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

然后安装节点和 npm:

nvm install node
node install npm
npm install npm

nvm install-latest-npm

执行 会找到更新 npm 的语句到最新版本,执行该命令,该命令应类似于 npm install -g [email protected],安装truffle后

npm install -g truffle

,执行上述命令时会出现权限问题,您必须执行

sudo chown -R $(whoami) <path to node_modules directory>

注意:上面的命令有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 安装:

npm install ganache --global

到你的 package.json 添加,

"scripts": {
  "ganache": "ganache --wallet.seed myCustomSeed"
}

然后执行,

npm run ganache

你应该能够看到输出一些东西就像 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

docker run -it ubuntu

on your container execute below:

apt-get update && apt-get upgrade 
apt-get install sudo build-essential python3 wget curl

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

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

then install node and npm with:

nvm install node
node install npm
npm install npm

after executing

nvm install-latest-npm

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 truffle

npm install -g truffle

there will be a permission issue in executing above command for which you've to execute

sudo chown -R $(whoami) <path to node_modules directory>

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:

npm install ganache --global

To your package.json add,

"scripts": {
  "ganache": "ganache --wallet.seed myCustomSeed"
}

Then execute,

npm run ganache

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 file truffle-config.js of your code, when you use it.

now execute truffle console

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文