2

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

Question:

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 ?

1 Answer 1

2

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:

sudoers:

Cmnd_Alias    RUBY = /path/to/runner
Defaults!RUBY env_file=/path/to/rubypathfile
ALL ALL=(ALL) RUBY

/path/to/rubypathfile:

PATH=/usr/local/bin:/usr/bin:/bin

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .