npm安装因EACCES失败:权限被拒绝

时间:2019-01-20 20:07:49

标签: node.js permissions

我正在尝试在Debian 9(Stretch)盒子上安装Node.js。最初,我以root用户身份运行以下命令:

curl -Lo node.tar.xz https://nodejs.org/dist/v10.15.0/node-v10.15.0-linux-x64.tar.xz
echo "4ee8503c1133797777880ebf75dcf6ae3f9b894c66fd2d5da507e407064c13b5 node.tar.xz" | sha256sum -c -
tar xJf node.tar.xz
cp -a node-v10.15.0-linux-x64/. /usr/local/

接下来,我使用常规用户帐户从我尝试构建的项目的源目录中运行npm install,并得到以下错误:

> git-validate@2.2.2 install /blah/node_modules/git-validate
> node bin/install

fs.js:115
    throw err;
    ^

Error: EACCES: permission denied, open '/blah/.git/hooks/pre-commit'
    at Object.openSync (fs.js:439:3)
    at Object.writeFileSync (fs.js:1190:35)
    at Object.exports.installHooks (/blah/node_modules/git-validate/lib/utils.js:248:12)
    at Object.<anonymous> (/blah/node_modules/git-validate/bin/install.js:3:7)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! git-validate@2.2.2 install: `node bin/install`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the git-validate@2.2.2 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!     /root/.npm/_logs/2019-01-20T19_55_48_025Z-debug.log

源目录是在当前运行npm install的同一用户帐户下克隆的git repo。

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

尝试执行此操作时出现类似错误。搜索了半个小时后找到了解决方案。尝试, sudo npm i -g artillery@1.6.0-2 -S 这是一项工作,但仍然可以为像我这样的人完成工作。