Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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

Ok, following on from this question, I'm still having problems getting things working. I'm doing this:

if [ "$(id -nu)" != 'your_user' ]; then
  exec sudo -Hu 'your_user' $0
which ruby
cd /path/to/my/app
rake db:backup

The problem is, which ruby is printing /usr/bin/ruby, but when I run it in a normal bash session I get /home/nick/.rvm/rubies/ruby-1.9.2-p136/bin/ruby, because I'm using RVM. So rake doesn't work because it's working from the wrong Ruby installation. Any ideas?

share|improve this question

Looks like Florian sorted this on the linked question

sudo -u 'user_name' -i

"runs the given command in a login shell, i.e. you get the same environment as if you login in text mode."

share|improve this answer
-H is not needed as -i does that already. – Florian Diesch May 19 '11 at 15:49
@Florian - Thanks for the clarification. This is all just magic spells for me at the moment :P – Skilldrick May 19 '11 at 15: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.