node.js 从 root 用户运行 bower,这可能吗?如何?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25672924/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run bower from root user, it's possible? How?
提问by ReynierPM
I have a local development server where I test a lot of things, now I'm playing with bower to manage the libraries' dependencies in my Symfony2 project. After getting NodeJS (v0.10.31) installed and bower (1.3.9), I tried to run the command sp:bower:installwhich belongs to Symfony2 SpBowerBundle from console as root:
我有一个本地开发服务器,我在其中测试了很多东西,现在我正在使用 bower 来管理我的 Symfony2 项目中的库依赖项。安装 NodeJS (v0.10.31) 和 bower (1.3.9) 后,我尝试sp:bower:install从控制台运行属于 Symfony2 SpBowerBundle的命令root:
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
I know that adding --allow-rootworks since I tested directly from bash but it apparently isn't allowed from the bundle command line. Now, is the only way to run bower as rootto add --allow-rootor does it exist another way ?
我知道添加是--allow-root有效的,因为我直接从 bash 进行了测试,但显然 bundle 命令行不允许这样做。现在,运行 bower 的唯一方法是root添加--allow-root还是以另一种方式存在?
回答by LPodolski
below answer is for symfony framework's bundle, but if you come here from googleusing phrase "bower root" you have two options to solve that:
下面的答案是针对 symfony 框架的包, 但是如果您使用短语“ bower root”从谷歌来到这里,您有两个选择来解决这个问题:
- add --allow-root to command
- set global bower config that will allow running bower as root
- 将 --allow-root 添加到命令
- 设置允许以 root 身份运行 bower 的全局 bower 配置
Option 1:you can run bower as root by typing:
选项 1:您可以通过键入以下命令以 root 身份运行 bower:
bower install --allow-root
root is allowed by setting --allow-root command parameter
通过设置 --allow-root 命令参数允许 root
Option 2:is using global setting that allows root, by creating file: /root/.bowerrcwhich have inside following configuration:
选项 2:使用允许 root 的全局设置,通过创建文件: /root/.bowerrc,其中包含以下配置:
{ "allow_root": true }
how to do this in SpBowerBundlesymfony bundle:
probably you haven't set sp_bower.allow_root to true in SpBowerBundle config
如何在SpBowerBundlesymfony bundle 中执行此操作:
可能您尚未在 SpBowerBundle 配置中将 sp_bower.allow_root 设置为 true
in bundle config, by default you have set something like this:
在捆绑配置中,默认情况下您已设置如下:
allow_root: false # optional
but you should have:
但你应该有:
allow_root: true
so in app/config/config.yml add this bundle config
所以在 app/config/config.yml 添加这个包配置
sp_bower:
allow_root: false # optional
bundle config reference (all settings): https://github.com/Spea/SpBowerBundle/blob/master/Resources/doc/configuration_reference.md
捆绑配置参考(所有设置):https: //github.com/Spea/SpBowerBundle/blob/master/Resources/doc/configuration_reference.md
回答by samwize
回答by Adrian Onu
If you are encountering this issue on Docker containers just add this line in your Dockerfile:
如果您在 Docker 容器上遇到此问题,只需在 Dockerfile 中添加以下行:
RUN echo '{ "allow_root": true }' > /root/.bowerrc
回答by keisar
This might be stupid but for me bower install --allow-rootdid not work but bower --allow-root installdid, using grunt-bower-install version 1.6.0
这可能很愚蠢,但对我来说bower install --allow-root没有bower --allow-root install用,但是用 grunt-bower-install 版本 1.6.0
This was on a docker running with root user, perhaps will save someone some time :)
这是在以 root 用户运行的 docker 上,也许会节省一些时间:)
回答by anoop
Faced similar issue when installing swagger-editor. Changed the following line in package.json from
安装 swagger-editor 时遇到类似问题。将 package.json 中的以下行从
"bower-install": "bower install"
to
到
"bower-install": "bower install --allow-root"
回答by André Luiz Machado
This works for me (add -u parameter on docker run)
这对我有用(在 docker run 上添加 -u 参数)
bash
docker run -it -v ${PWD}:/www -w /www -u node node ./node_modules/bower/bin/bower install
bash
docker run -it -v ${PWD}:/www -w /www -u node node ./node_modules/bower/bin/bower install
回答by HariKishore
For My case it is in Pom.xml where i have added as an argument as below:
对于我的情况,它在 Pom.xml 中,我在其中添加了一个参数,如下所示:
<executable>bower</executable>
<arguments>
<argument>install</argument>
<argument>--allow-root</argument>
</arguments>
If need to avoid this --allow--root parameter we can do a compile out of root user
如果需要避免这个 --allow--root 参数,我们可以使用 root 用户进行编译

