Take the 2-minute tour ×

I need to write some bash scripts and rake scripts to setup my server. However, I'm afraid that it will mess up with sudo in rvm because packages installation in ubuntu require sudo and gem installation doesn't need sudo.

Anyone has some suggestions?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Write two scripts, one for tasks that require sudo, and one for tasks not needing it. Your sudo tasks will have to run first because they're going to do your apt installs. Afterwards run your non-sudo script.

You definitely don't want to run RVM, or gems using sudo if it will be affecting something in rvm's sandbox.

I've set up several hosts lately, and that's the order I do my installs.

share|improve this answer
No other solutions? –  Chamnap Jan 8 '11 at 4:46
Not really. I don't see a lot of choices; You can run one script as sudo or as root, then the other as yourself. The other alternative is one script with some commands preceded by sudo when you need root's privileges. Personally, I'd keep the functionality segmented into the "haves" and the "have nots" so a task that isn't supposed to be run as root has no chance of it occurring. –  the Tin Man Jan 8 '11 at 5:01
Well, this solution is a bit hard to achieve since my script is to install nginx + passenger + rvm. First, install necessary packages to compile nginx, install gem, last configure nginx which require sudo again. –  Chamnap Jan 8 '11 at 6:15
I agree with the Tin Man in keeping the functionality in two separate scripts, but one option might be to use sudo -u to call the user-level script from the one running as root if you're really intent on only running a single command. –  kejadlen Jan 8 '11 at 7:15
sudo -u? can you give me example? –  Chamnap Jan 8 '11 at 7:28

Your Answer


