My context:

  • ruby-enterprise 1.8.7, on a CentOS 5
  • ruby and gem are installed in /usr/local/bin
  • ./runner: runs correctly
  • sudo ./runner

    Rails requires RubyGems >= 1.3.2. Please install RubyGems and try again: http://rubygems.rubyforge.org

    (because sudo has a limited PATH)

  • sudo PATH=$PATH ./runner: runs correctly, as runner has /usr/local/bin in its PATH again


Are there other alternatives (possibly more elegant - with minimal changes) to launch runner with sudo, when gem is not in /bin or /usr/bin ?

Those I would think of (but not satisfied with):

  • putting a symlink to gem in /usr/bin
  • modifying runner ?
  • modifying sudoers ?

Maybe there is a way with a config file or a command line argument to runner ?


You should be able to use the env_file option in sudoers and put your path specification in a file that it points to. Something like:


Cmnd_Alias    RUBY = /path/to/runner
Defaults!RUBY env_file=/path/to/rubypathfile



You may also find the env_keep option useful.

Take a look at sudo sudo -V | less and see if it tells you anything of interest. Particularly do a case-insensitive search for "path" or "ruby".

  • Thanks Dennis, especially for the sudo sudo -V tip. – David142 Aug 27 '10 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.