Skip to content
Joe James edited this page Mar 4, 2014 · 2 revisions

Because sudo resets the $PATH environment variable, running a Ruby command through sudo will not invoke the currently selected Ruby, but will invoke the system Ruby instead. To solve this problem you need to invoke sudo commands using chruby-exec:

sudo chruby-exec ruby-1.9.3-p448 -- rake --version

Or, you can obtain a root prompt first using sudo -s, then switch Ruby, then run the command:

# Obtain root prompt
sudo -s
# Initialize chruby and switch Ruby
source /usr/local/share/chruby/chruby.sh
chruby ruby-1.9.3-p448
# Run the command we wanted
rake --version
Clone this wiki locally