【问题标题】:Permission denied while installing Yo安装 Yo 时权限被拒绝
【发布时间】:2015-06-01 10:06:57
【问题描述】:

我正在尝试设置 yo 以将角度生成器用于项目。我正在按照此处详述的步骤进行操作:http://yeoman.io/learning/index.html

我已经安装了 Node.js 和 NPM。

但是当我使用命令时:

sudo npm install -g yo bower grunt-cli

它失败了,我得到了这个错误:

> spawn-sync@1.0.11 postinstall /usr/lib/node_modules/yo/node_modules/cross-spawn/node_modules/spawn-sync
> node postinstall


fs.js:439
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: EACCES, permission denied '/usr/lib/node_modules/yo/node_modules/cross-spawn/node_modules/spawn-sync/package.json'
    at Object.fs.openSync (fs.js:439:18)
    at Object.fs.writeFileSync (fs.js:978:15)
    at Object.<anonymous> (/usr/lib/node_modules/yo/node_modules/cross-spawn/node_modules/spawn-sync/postinstall.js:20:6)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:935:3
npm ERR! Linux 3.13.0-24-generic
npm ERR! argv "node" "/usr/bin/npm" "install" "-g" "yo"
npm ERR! node v0.10.37
npm ERR! npm  v2.11.0
npm ERR! code ELIFECYCLE

npm ERR! spawn-sync@1.0.11 postinstall: `node postinstall`
npm ERR! Exit status 8
npm ERR! 
npm ERR! Failed at the spawn-sync@1.0.11 postinstall script 'node postinstall'.
npm ERR! This is most likely a problem with the spawn-sync package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node postinstall
npm ERR! You can get their info via:
npm ERR!     npm owner ls spawn-sync
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/vincent/npm-debug.log

我尝试使用chmod 777 on /usr/lib/node_modules,但似乎效果不佳。

我可以安装 Bower 和 Grunt,它可以工作,但是当我尝试安装 Yo 时,它每次都失败...

我不知道该怎么做,因为我尝试使用 chmodchown 的所有方法都不起作用。

感谢你们的帮助! :)

【问题讨论】:

    标签: angularjs yeoman yeoman-generator-angular yo


    【解决方案1】:

    我通过以下方式解决了这个问题:

    sudo npm install -g yo --unsafe-perm

    nyakto 在此bug report 中建议使用--unsafe-perm

    编辑 - 意识到这是@Stephan 在他的回答中发布的 URL。

    我不知道 --unsafe-perm 的具体细节 - 我只能说它允许我安装 yo 而不会遇到与 OP 非常相似/相同的错误。

    【讨论】:

    • 据我了解,在这里使用 sudo 不是一个好主意,请参阅this answer 以获得更好的解决方案
    【解决方案2】:

    github repo 中的评论解决了我的问题。基本上只需要更新节点版本。列出步骤以供将来参考:

    sudo npm cache clean -f
    sudo npm install -g n
    sudo n stable
    node -v
    

    干杯

    【讨论】:

      【解决方案3】:

      【讨论】:

      • 感谢您的帮助!欣赏它;)
      【解决方案4】:

      我有同样的问题。显然是约曼的常见问题。执行以下操作解决了我的问题尝试删除/Users/yourusername/.config/configstore/ 目录中的所有文件,然后照常运行yo 命令。

      【讨论】:

      • 感谢您的回复,但我找不到此路径。我在Linux上,这不是你给我的Windows路径吗?
      • 哦,是的,这是 Windows 路径。如果您使用的是 linux 环境。在您的主目录中查找文件夹名称 .config。它是隐藏的,所以按 ctrl+H 显示文件夹。您应该在其中找到一个名为 configstore 的文件夹。清理文件夹并尝试再次运行yo
      • 我试过了,但我仍然得到同样的错误。在文件夹 configstore 中,有 3 个文件,但都与我成功安装的 Bower 相关。所以我想删除这些文件对安装 Yo 没有任何作用。
      【解决方案5】:

      我也有同样的问题,在 linuxmint 17 下。 因为我使用 nodejs 0.10,并且我将 npm 升级到 2.X。

      尝试重新安装nodejs并选择正确的版本 https://github.com/nodesource/distributions

      祝你好运!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-02-10
        • 2020-08-27
        • 2015-10-13
        • 1970-01-01
        • 1970-01-01
        • 2023-04-10
        • 1970-01-01
        相关资源
        最近更新 更多