在 MacOs 设备上安装 Truffle 时出错

在 MacOs 设备上安装 Truffle 时出错

我正在尝试将 truffle 安装到我的 MacOs 设备上,但有一个我无法解决的持续问题。这似乎是权限问题。以下是我尝试的方法:

我修改了当前用户的权限:

sudo chown -R ${whoami} /usr/local/bin/truffle
sudo chown -R ${whoami} /usr/local/bin/node_modules

我切换到root用户:

sudo su

我尝试通过 sudo 安装它:

sudo npm install -g truffle

以下是日志输出:

node-pre-gyp WARN Using request for node-pre-gyp https download
    node-pre-gyp WARN Pre-built binaries not installable for [email protected] and [email protected] (node-v83 ABI, unknown) (falling back to source compile with node-gyp)
    node-pre-gyp WARN Hit error EACCES: permission denied, mkdir '/usr/local/lib/node_modules/truffle/node_modules/sqlite3/lib/binding'
    gyp WARN EACCES current user ("nobody") does not have permission to access the dev dir "/Users/macbookpro/Library/Caches/node-gyp/14.16.1"
    gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/truffle/node_modules/sqlite3/.node-gyp"
    gyp WARN install got an error, rolling back install
    gyp WARN install got an error, rolling back install
    gyp ERR! configure error
    gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/truffle/node_modules/sqlite3/.node-gyp'
    gyp ERR! System Darwin 19.6.0
    gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/usr/local/lib/node_modules/truffle/node_modules/sqlite3/lib/binding/node-v83-darwin-x64/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/usr/local/lib/node_modules/truffle/node_modules/sqlite3/lib/binding/node-v83-darwin-x64" "--napi_version=7" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v83"
    gyp ERR! cwd /usr/local/lib/node_modules/truffle/node_modules/sqlite3
    gyp ERR! node -v v14.16.1
    gyp ERR! node-gyp -v v5.1.0
    gyp ERR! not ok
    node-pre-gyp ERR! build error
    node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/truffle/node_modules/sqlite3/lib/binding/node-v83-darwin-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/usr/local/lib/node_modules/truffle/node_modules/sqlite3/lib/binding/node-v83-darwin-x64 --napi_version=7 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v83' (1)
    node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/truffle/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
    node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
    node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1048:16)
    node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
    node-pre-gyp ERR! System Darwin 19.6.0
    node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/truffle/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
    node-pre-gyp ERR! cwd /usr/local/lib/node_modules/truffle/node_modules/sqlite3
    node-pre-gyp ERR! node -v v14.16.1
    node-pre-gyp ERR! node-pre-gyp -v v0.11.0
    node-pre-gyp ERR! not ok
    Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/truffle/node_modules/sqlite3/lib/binding/node-v83-darwin-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/usr/local/lib/node_modules/truffle/node_modules/sqlite3/lib/binding/node-v83-darwin-x64 --napi_version=7 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v83' (1)
    
    > [email protected] postinstall /usr/local/lib/node_modules/truffle
    > node ./scripts/postinstall.js
    
    Error: EACCES: permission denied, mkdir '/Users/macbookpro/.config/truffle'
    You don't have access to this file.

相关内容