使用$ sudo bundle exec …引发’bundle:command not found’错误

我在Ubuntu服务器上安装了rbenv。 我可以进入我的应用程序目录并运行$ bundle而不会出现问题,但是我需要运行$ sudo bundle exec ...这会给我一个错误:

bundle:找不到命令

为什么这样,我该如何解决?

Dan Carley的rbenv-sudo看起来会像你想要的那样:

rbenv-sudo是rbenv的插件,允许您在sudo会话中运行rbenv提供的Rubies和Gems。

本文提供了有关其工作原理的更详细说明: Sudo Rbenv Me a Sandwich

不完全确定,但也许这对你有用:

 sudo -i -u $USER bundle exec... 

要么

 sudo -i -u username_with_correct_env bundle exec... 

为什么你得到错误已经解决了。 但我能够说:

 sudo /full/path/to/bundle exec ... 

在我的情况下,我使用rbenv,所以我不得不:

 sudo /home/renier/.rbenv/shims/bundle exec ... 

那很有效。 要让sudo不要求输入密码,您需要为此配置/etc/sudoers文件。 请参阅https://serverfault.com/a/160587 。

要在不使用rbenv或rvm的情况下执行此操作,请执行以下操作:

sudo -E bundle exec ...

  -E The -E (preserve environment) option will override the env_reset option in sudoers(5). It is only available when either the matching command has the SETENV tag or the setenv option is set in sudoers(5). sudo will return an error if the -E option is specified and the user does not have permission to preserve the environment.