58

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:install which belongs to Symfony2 SpBowerBundle from console as 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-root works 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 root to add --allow-root or does it exist another way ?

Ehvince
  • 17,274
  • 7
  • 58
  • 79
ReynierPM
  • 17,594
  • 53
  • 193
  • 363

8 Answers8

149

below answer is for symfony framework's bundle, but if you come here from google using phrase "bower root" you have two options to solve that:

  1. add --allow-root to command
  2. set global bower config that will allow running bower as root

Option 1: you can run bower as root by typing:

bower install --allow-root

root is allowed by setting --allow-root command parameter

Option 2: is using global setting that allows root, by creating file: /root/.bowerrc which have inside following configuration:

{ "allow_root": true }

how to do this in SpBowerBundle symfony bundle:
probably you haven't set sp_bower.allow_root to true in SpBowerBundle config

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

sp_bower:
    allow_root: false # optional

bundle config reference (all settings): https://github.com/Spea/SpBowerBundle/blob/master/Resources/doc/configuration_reference.md

LPodolski
  • 2,888
  • 4
  • 21
  • 24
  • where do you put allow_root: true ?? – Tyvain Jan 12 '15 at 08:37
  • 1
    @Tyvain, I had the same question. I installed Bower on FreeBSD 10 without Symfony. Type: cd / Then ee .bowerrc. Add there: { "allow_root": true } See http://bower.io/docs/config/ for more information on .bowerrc file. – blablabla Feb 21 '15 at 14:42
  • 1
    The `allow_root` value has to be set in your `app/config/config.yml`. Just follow the link in the answer. – althaus Mar 04 '15 at 08:19
  • 1
    Option 2 Worked for me. Thanks. – Behnam Mar 25 '17 at 17:34
18

If you are encountering this issue on Docker containers just add this line in your Dockerfile:

RUN echo '{ "allow_root": true }' > /root/.bowerrc
Adrian Onu
  • 671
  • 7
  • 13
17

I fixed a similar problem by changing the directory permissions:

sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
samwize
  • 25,675
  • 15
  • 141
  • 186
5

This might be stupid but for me bower install --allow-root did not work but bower --allow-root install did, using grunt-bower-install version 1.6.0

This was on a docker running with root user, perhaps will save someone some time :)

Ehvince
  • 17,274
  • 7
  • 58
  • 79
keisar
  • 5,266
  • 5
  • 28
  • 28
3

Faced similar issue when installing swagger-editor. Changed the following line in package.json from

"bower-install": "bower install"

to

"bower-install": "bower install --allow-root"
anoop
  • 103
  • 2
  • 8
3

This works for me (add -u parameter on docker run)

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

2

For My case it is in Pom.xml where i have added as an argument as below:

<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

HariKishore K
  • 399
  • 3
  • 6
0

remover / delete bower_components and reinstall bower

bower install
Deni Al Farizi
  • 1,547
  • 1
  • 8
  • 5