【问题标题】:Run bower from root user, it's possible? How?从root用户运行凉亭,有可能吗?如何?
【发布时间】:2014-09-04 18:45:11
【问题描述】:

我有一个本地开发服务器,我在其中测试了很多东西,现在我正在使用 bower 来管理 Symfony2 项目中库的依赖项。在安装 NodeJS (v0.10.31) 和 bower (1.3.9) 后,我尝试从控制台以 root 运行属于 Symfony2 SpBowerBundle 的命令 sp:bower:install

Symfony > sp:bower:install
Installing bower dependencies for "TemplateBundle" into "/var/www/html/tanane/src/Tanane/TemplateBundle/Resources/config/bower/../../public/components"

bower ESUDO         Cannot be run with sudo

Additional error details:
Since bower is a user command, there is no need to execute it with superuser permissions.
If you're having permission errors when using bower without sudo, please spend a few minutes learning more about how your system should work and make any necessary repairs.

http://www.joyent.com/blog/installing-node-and-npm
https://gist.github.com/isaacs/579814

You can however run a command with sudo using --allow-root option

我知道添加 --allow-root 是有效的,因为我直接从 bash 进行了测试,但显然不允许从 bundle 命令行添加。现在,以 root 运行 bower 以添加 --allow-root 的唯一方法是还是以其他方式存在?

【问题讨论】:

  • echo '{ "allow_root": true }' > /root/.bowerrc

标签: node.js symfony bower


【解决方案1】:

下面的答案是针对 symfony 框架的捆绑包, 但如果您使用短语“bower root”从谷歌来到这里,您有两种选择来解决这个问题:

  1. 将 --allow-root 添加到命令
  2. 设置将允许的全局凉亭配置 以 root 身份运行 bower

选项 1:您可以通过键入以下内容以 root 身份运行 bower:

bower install --allow-root

通过设置--allow-root命令参数允许root

选项 2: 正在使用允许 root 的全局设置,通过创建文件: /root/.bowerrc 其中有以下配置:

{ "allow_root": true }

如何在 SpBowerBundle symfony 包中做到这一点:
可能你没有在 SpBowerBundle 配置中将 sp_bower.allow_root 设置为 true

在捆绑配置中,默认情况下您已设置如下内容:

allow_root: false # optional

但你应该有:

allow_root: true

所以在 app/config/config.yml 添加这个包配置

sp_bower:
    allow_root: false # optional

捆绑配置参考(所有设置): https://github.com/Spea/SpBowerBundle/blob/master/Resources/doc/configuration_reference.md

【讨论】:

  • 你把 allow_root: true 放在哪里??
  • @Tyvain,我也有同样的问题。我在没有 Symfony 的 FreeBSD 10 上安装了 Bower。类型:cd / 然后 ee .bowerrc。在此处添加: { "allow_root": true } 有关 .bowerrc 文件的更多信息,请参阅bower.io/docs/config
  • allow_root 值必须在您的app/config/config.yml 中设置。只需点击答案中的链接即可。
  • 选项 2 为我工作。谢谢。
【解决方案2】:

fixed通过更改目录权限也出现类似问题:

sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config

【讨论】:

    【解决方案3】:

    如果您在 Docker 容器上遇到此问题,只需在 Dockerfile 中添加以下行:

    RUN echo '{ "allow_root": true }' > /root/.bowerrc
    

    【讨论】:

    • 我必须在哪里添加 docker 文件?
    【解决方案4】:

    这可能很愚蠢,但对我来说 bower install --allow-root 不起作用,但 bower --allow-root install 起作用了,使用 grunt-bower-install 版本 1.6.0

    这是在一个以 root 用户运行的 docker 上,也许会节省一些时间:)

    【讨论】:

      【解决方案5】:

      安装 swagger-editor 时遇到类似问题。 将 package.json 中的以下行从

      "bower-install": "bower install"
      

      "bower-install": "bower install --allow-root"
      

      【讨论】:

        【解决方案6】:

        这对我有用(在 docker run 上添加 -u 参数)

        bash docker run -it -v ${PWD}:/www -w /www -u node node ./node_modules/bower/bin/bower install

        【讨论】:

          【解决方案7】:

          对于我来说,它是在 Pom.xml 中,我在其中添加了如下参数:

          <executable>bower</executable>
           <arguments>
           <argument>install</argument>
            <argument>--allow-root</argument>
           </arguments>
          

          如果需要避免这个 --allow--root 参数,我们可以使用 root 用户进行编译

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-08-08
            • 2014-02-24
            • 1970-01-01
            • 2014-03-14
            • 2015-12-12
            相关资源
            最近更新 更多