我想在 npm 上安装机制,我试图运行这一行 sudo npm install -g 机制,但它给了我错误,我不明白这个错误



我想在我的nginx服务器上安装mechanic。

执行sudo npm install -g mechanic时出现此错误:

tigaron@galaxybrainpower:/var/www/tigaron$ sudo npm install -g mechanic
/usr/bin/mechanic -> /usr/lib/node_modules/mechanic/bin/mechanic
> fs-ext@2.0.0 install /usr/lib/node_modules/mechanic/node_modules/fs-ext
> node-gyp configure build
gyp WARN EACCES current user ("nobody") does not have permission to access the dev dir "/home/tigaron/.cache/node-gyp/10.20.1"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/lib/node_modules/mechanic/node_modules/fs-ext/.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/lib/node_modules/mechanic/node_modules/fs-ext/.node-gyp'
gyp ERR! System Linux 4.15.0
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /usr/lib/node_modules/mechanic/node_modules/fs-ext
gyp ERR! node -v v10.20.1
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fs-ext@2.0.0 install: `node-gyp configure build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the fs-ext@2.0.0 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/tigaron/.npm/_logs/2020-05-24T06_29_26_857Z-debug.log

这是怎么回事?如何修复此错误并继续安装?

这个答案解决了我在安装不同软件包时遇到的相同问题。

显然,在全局构建包时使用nobody用户,但目录归root所有,因此它无法获得权限。将npm配置为使用以下命令root是答案的建议。

npm -g config set user root

最新更新