4

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 ... and this gets me an error:

bundle: command not found

Why is this and how can I fix it?

Undistraction
  • 42,754
  • 56
  • 195
  • 331

4 Answers4

5

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... 
rainkinz
  • 10,082
  • 5
  • 45
  • 73
4

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

Chris Salzberg
  • 27,099
  • 4
  • 75
  • 82
  • You're correct. That would be the way to go, but unfortunately I'm running this command from a Capistrano deploy, and this causes the deploy to hang asking for a password, but without the usual prompt. – Undistraction Feb 01 '13 at 14:25
3

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.

Community
  • 1
  • 1
renier
  • 768
  • 6
  • 9
1

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.
Chris
  • 491
  • 5
  • 11