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?

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

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.

  • the sudo is not for the command...its for running the command as the deploy user – Matt Elhotiby 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'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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