Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have this command:

ubuntu@ip-10:~$ sudo su deploy -c 'rvm install 1.9.3' 
bash: rvm: command not found

I also tried:

ubuntu@ip-10:~$ sudo su deploy -c 'source /home/deploy/.bashrc && rvm install 1.9.3' 
bash: rvm: command not found

Same result. Not sure what's happening because when I do this:

sudo su deploy
deploy@ip-10-101-6-147:/home/ubuntu$ rvm install 1.9.3
Fetching yaml-0.1.4.tar.gz to /home/deploy/.rvm/archives

All works great. But I can't do that because this is for a shell script. Why doesn't it work in the first two instances?

share|improve this question

migrated from stackoverflow.com Jul 31 '12 at 2:26

This question came from our site for professional and enthusiast programmers.

    
what happens if you add dash after su? E.g.: sudo su - deploy -c 'rvm install 1.9.3'? It works? –  kenorb Jul 31 '12 at 22:44

2 Answers 2

I think when you use sudo, it creates a new sub-shell without all the env variables.

If I remember correctly, you have to use the command rvmsudo, in order for rvm to have the proper variables.

share|improve this answer
    
the sudo is not for the command...its for running the command as the deploy user –  Tamer Jul 30 '12 at 22:27

Seems like you are trying to simply switch user and run a command that deploys some files in to that user's home.

su deploy -c 'rvm install 1.9.3'

You should not need to elevate privileges with sudo to run su, and if you need sudo to run rvm then you probably can do it with

su deploy -c 'sudo rvm install 1.9.3'
share|improve this answer

Your Answer

 
discard

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.