Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

    (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 ?

share|improve this question
up vote 2 down vote accepted

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".

share|improve this answer
Thanks Dennis, especially for the sudo sudo -V tip. – David142 Aug 27 '10 at 8:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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