I'm on Ubuntu 17.04. Not sure if I have bower installed or not:
$ sudo npm install -g bower
/usr/bin/bower -> /usr/lib/node_modules/bower/bin/bower
/usr/lib
└── bower@1.8.0 When I try to check and I get errors:
$ bower -V
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.
You can however run a command with sudo using --allow-root option
Stack trace:
Error: Cannot be run with sudo at createError (/usr/lib/node_modules/bower/lib/util/createError.js:4:15) at rootCheck (/usr/lib/node_modules/bower/lib/util/rootCheck.js:26:24) at Object.<anonymous> (/usr/lib/node_modules/bower/lib/bin/bower.js:33:1) at Module._compile (module.js:571:32) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Module.require (module.js:498:17) at require (internal/module.js:20:19)
Console trace:
Error at StandardRenderer.error (/usr/lib/node_modules/bower/lib/renderers/StandardRenderer.js:81:37) at rootCheck (/usr/lib/node_modules/bower/lib/util/rootCheck.js:26:18) at Object.<anonymous> (/usr/lib/node_modules/bower/lib/bin/bower.js:33:1) at Module._compile (module.js:571:32) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Module.require (module.js:498:17) at require (internal/module.js:20:19)
System info:
Bower version: 1.8.0
Node version: 7.10.0
OS: Linux 4.9.15-x86_64-linode81 x64When I try to install packages with my program I get errors too:
[localhost] local: bower install
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.
You can however run a command with sudo using --allow-root option
Fatal error: local() encountered an error (return code 1) while executing 'bower install'
Aborting.Any ideas how I can fix this?
51 Answer
You seem to be running bower as root or with sudo, which you should not do. It is meant to run only with restricted user privileges and contains a safety check to abort if it runs with root rights.
This is implemented for security reasons, because bower will download and execute untrusted code to do its job. That should definitely not be done as root for various reasons, especially not on a production server.
As the error message suggested, there is a --allow-root switch to override the safety check and run it even though you are root.
However, the optimal and secure way to go would be to create a separate user account with limited privileges and use that one instead of doing everything as root, which does not only include bower.