EACCES:使用 sudo 时权限被拒绝

EACCES:使用 sudo 时权限被拒绝

我正在尝试使用 NPM 安装节点包,但它只是给出了权限错误。昨天我可以毫无问题地安装软件包,但由于某种原因它已停止工作。

asgeir@1e19udt0shu6:~/nodejs/first_test_app$ sudo npm install sharp

> [email protected] install /home/asgeir/nodejs/first_test_app/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)

info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.7.4/libvips-8.7.4-linux-x64.tar.gz
ERR! sharp EACCES: permission denied, open '/home/asgeir/nodejs/first_test_app/node_modules/sharp/9016-libvips-8.7.4-linux-x64.tar.gz'
info sharp Attempting to build from source via node-gyp but this may fail due to the above error
info sharp Please see https://sharp.pixelplumbing.com/page/install for required dependencies
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/home/asgeir/nodejs/first_test_app/node_modules/sharp/build'
gyp ERR! System Linux 2.6.32-042stab133.2
gyp ERR! command "/usr/local/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/asgeir/nodejs/first_test_app/node_modules/sharp
gyp ERR! node -v v10.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/asgeir/.npm/_logs/2019-07-17T06_16_33_097Z-debug.log

经过一番谷歌搜索后,我发现一些灵魂人物也遇到了同样的错误。他们显然是通过重新安装 NPM 和 NodeJS 来让它工作的,但我没有取得任何成功。关于如何克服这个错误有什么想法吗?

答案1

经过另一次极端谷歌搜索后,我找到了这个解决方案:

使用此命令强制 NPM 安装 Sharp 软件包。

sudo npm install --unsafe-perm=true --allow-root

如果需要下载特定模块,请注明需要下载的依赖项。

sudo npm install dependency-name --unsafe-perm=true --allow-root

我不太了解 Linux 礼仪,但这个命令感觉像是犯罪。但它确实有效!

编辑:如果它不适合你,请尝试这篇文章是我在SO上找到的。

相关内容