无法在ubuntu 16.4上安装节点8依赖项

时间:2017-06-15 14:01:37

标签: node.js npm

我无法安装我的项目(在节点6下运行良好)。这是由于节点8的依赖性,除了被弃用之外,还试图写入没有权限的地方。

ubuntu@ip-xxxxxxx:~/share_place/bin$ sudo npm i
npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
npm WARN deprecated minimatch@0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch@0.4.0: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated jade@0.26.3: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated to-iso-string@0.0.2: to-iso-string has been deprecated, use @segment/to-iso-string instead.
npm WARN deprecated minimatch@0.3.0: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated graceful-fs@1.2.3: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs@^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
npm ERR! code 1
npm ERR! Command failed: /usr/bin/git clone --depth=1 -q -b v0.5.5 git://github.com/bookchin/node-ntp-client.git /home/ubuntu/.npm/_cacache/tmp/git-clone-cd074428
npm ERR! /home/ubuntu/.npm/_cacache/tmp/git-clone-cd074428/.git: Permission denied
npm ERR! 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ubuntu/.npm/_logs/2017-06-15T13_45_37_010Z-debug.log
ubuntu@ip-xxxxx:~/share_place/bin$ node -v
v8.1.2

这对我们来说非常令人沮丧,因为我们正在Windows和Mac下开发而没有问题,但现在我们陷入了预生产阶段。

非常欢迎任何帮助,谢谢

1 个答案:

答案 0 :(得分:4)

如果npm以root身份运行(因为sudo),它将在执行外部脚本/程序(如git)之前删除root权限。 By default它会设置为nobody

这会导致权限问题,因为nobody很可能不允许写入目录/home/ubuntu/.npm/_cacache/tmp/git-clone-cd074428/(因此" Permission denied" 错误)。

最好的解决方案是根本不使用sudo。在您的情况下,仅安装本地依赖项,它比通常情况更不明显,其中sudo用于全局安装(-g)。

如果某些文件/目录现在属于/home/ubuntu/.npm/,也许您可​​能必须清除root中的权限:

sudo chown -R $USER /home/ubuntu/.npm