Ubuntu
EACCES:使用 sudo 時權限被拒絕
我正在嘗試使用 NPM 安裝節點包,但它只是給出了權限錯誤。昨天我可以毫無問題地安裝軟體包,但由於某種原因它已經停止工作。
asgeir@1e19udt0shu6:~/nodejs/first_test_app$ sudo npm install sharp > sharp@0.22.1 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 first_test_app@1.0.0 No repository field. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! sharp@0.22.1 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 sharp@0.22.1 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
經過一番Google搜尋,我發現一些倒靈魂的人遇到了同樣的錯誤。他們顯然是通過重新安裝 NPM 和 NodeJS 讓它工作的,但我沒有成功。關於如何克服這個錯誤的任何想法?
在另一次極端Google搜尋之後,我找到了這個解決方案:
使用此命令強制 NPM 安裝 Sharp 包。
sudo npm install --unsafe-perm=true --allow-root
如果需要下載特定模組,請提及需要下載的依賴項。
sudo npm install dependency-name --unsafe-perm=true --allow-root
我不太了解 Linux 的禮儀,但是這個命令感覺像是在犯罪。它雖然有效!
編輯:如果它不適合你,試試我在 SO 上找到的這篇文章。