我在 Ubuntu 17.04 上。不确定我是否安装了 bower:
$ sudo npm install -g bower
/usr/bin/bower -> /usr/lib/node_modules/bower/bin/bower
/usr/lib
└── [email protected]
当我尝试检查并收到错误时:
$ 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.
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
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 x64
当我尝试使用我的程序安装软件包时,也会收到错误:
[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.
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
Fatal error: local() encountered an error (return code 1) while executing 'bower install'
Aborting.
有什么想法可以修复此问题吗?
答案1
bower
您似乎以 root 身份或使用运行sudo
,但您不应该这样做。它只能以受限用户权限运行,并且包含安全检查,如果以 root 权限运行,则会中止。
这是出于安全原因而实施的,因为bower
将下载并执行不受信任的代码来完成其工作。出于各种原因,绝对不应该以 root 身份执行此操作,尤其是在生产服务器上。
正如错误消息所暗示的,有一个--allow-root
开关可以覆盖安全检查,即使您是 root 权限也可以运行它。
但是,最佳且安全的方法是创建一个具有有限权限的单独用户帐户并使用该帐户,而不是以 root 身份执行所有操作,这不仅包括bower
。