Using $ sudo bundle exec … raises 'bundle: command not found' error

前端 未结 4 696
粉色の甜心
粉色の甜心 2020-12-11 09:16

I have installed rbenv on an Ubuntu sever. I can cd into my application directory and run $ bundle without issue, however I need to run $ sudo bundle exec

相关标签:
4条回答
  • 2020-12-11 09:39

    Not entirely sure, but maybe this would work for you:

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

    or

    sudo -i -u username_with_correct_env bundle exec... 
    
    0 讨论(0)
  • 2020-12-11 09:47

    Why you get the error has been addressed already. But I was able to get around it by saying:

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

    In my case, I'm using rbenv, so I had to:

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

    That worked. To get sudo to not ask for a password, you would need to configure your /etc/sudoers file for this. See https://serverfault.com/a/160587.

    0 讨论(0)
  • 2020-12-11 09:54

    Dan Carley's rbenv-sudo looks like it will do what you want:

    rbenv-sudo is a plugin for rbenv that allows you to run rbenv-provided Rubies and Gems from within a sudo session.

    A more detailed explanation of how it works is provided in this article: Sudo Rbenv Me a Sandwich

    0 讨论(0)
  • 2020-12-11 09:55

    To do this without using rbenv or rvm, do this:

    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.
    
    0 讨论(0)
提交回复
热议问题