Nginx + Ruby on Rails on a Gentoo Slice

31 Jul 2007

Ahoy Railers, Gentooers, Nginxers and other ridiculous sounding words!

I’ve recently found myself setting up a number of machines at Slicehost with a Gentoo install. Why Gentoo you ask? Why not Ubuntu? Well, I must say that I’m always tempted to try Ubuntu because of the speed of installation and the fact that I don’t have to wait for things to compile. In fact, the last few slices started with Ubuntu. They each ended abruptly when I tried:

sudo apt-get install nginx

only to find that Ubuntu didn’t know about Nginx. Didn’t even know!

Sure, I can install Nginx from source but then what’s the point of even having a package manager? Gentoo gives me 7 versions of Nginx and remember which other apps each version works and plays well with. 7 versions. Ubuntu has none.

So I keep going back to Gentoo. And to make life easier on myself I decided to actually record my steps the last time so I don’t have to think about it next time. Here’s a handy little script to get you rollin’ on a bleeding-edge Gentoo slice in no time.

# login as root before running this script
# edit the username to reflect your preferences.
# save the script to a file and run it like:
# > /bin/bash this_script &
# remember the ampersand on the end and it'll run until it's done even if you disconnect

my_favorite_username='whatever_you_like_to_login_with'

# this bit will require some user interaction
useradd -m $my_favorite_username
useradd -d /www -m www
passwd $my_favorite_username
passwd www

# from here on we're rollin'
echo 'ACCEPT_KEYWORDS=~amd64' >> /etc/make.conf
echo 'USE="gif imagemagick innodb jbig jpeg jpeg2k pdf perl png mysql python ruby sqlite3 ssl svg truetype unicode xml xpm pcre -php -wmf -tiff -lcms -postgres"' >> /etc/make.conf
emerge --sync
emerge sudo
echo "$my_favorite_username        ALL=(ALL)       NOPASSWD: ALL" >> /etc/sudoers
emerge -C ssmtp
emerge vim ruby rubygems nginx subversion dev-db/mysql postfix vixie-cron
gem install --include-dependencies --no-ri --no-rdoc rails mongrel mongrel_cluster tzinfo BlueCloth RedCloth mysql sqlite3-ruby rspec zentest capistrano nginx_config_generator
gem install --include-dependencies --no-ri --no-rdoc activeresource --source http://gems.rubyonrails.org
emerge --config =dev-db/mysql-5.0.44-r1
rc-config add mysql default
/etc/init.d/mysql start
rc-config add nginx default
/etc/init.d/nginx start
rc-config add postfix default
/etc/init.d/postfix start
  • Alex Gretlein said: Nginx is in Universe since Ubuntu Feisty. If binary packages were the only advantage, you could always use Debian or any other distro. There are probably other advantages to Ubuntu - such as Upstart (http://upstart.ubuntu.com). And of course there are also advantages to Gentoo. (And you can use upstart on Gentoo.)
  • cbt said: Nice script. I didn't know there were issues with Ubuntu and Nginx. I'll try out your script on one of my slice ;p
  • ynw said: Compiled Nginx on Ubuntu from source with no trouble.
  • Jack Danger said: @ynw I'm sure you can compile it, I just don't want to bother learning another distro when I've got so much Gentoo experience. Plus I'm not sure if Ubuntu will keep the Nginx code as updated as Gentoo unstable does. Like so many other things: use what works for you.
  • Koba said: I think there might be an error in your script. This line: /etc/init.d/mysql nginx start should probably be: /etc/init.d/nginx start Thanks for contributing... I'm going to do something similar.
  • Jack Danger said: Thanks Koba - I'm not sure how that got in there. Fixed!
  • koba said: No problem. Thanks for making my move to Gentoo smoother.
  • Gilang Chandrasa said: FYI, there is nginx package for Ubuntu, but not as update as nginx package for Gentoo. you need to activate universe, so your Ubuntu can get the package. I would like to try Gentoo, considering Gentoo update faster than most of distro.
  • Nicholas Orr said: That is awesome! I've thought to script my Gentoo setup's... I do the same thing over and over again, it's not like I have to actually be sitting there watching it. Thanks for the idea :) One query on the sudo part. If i read the correctly - if you do sudo cmd - that'll run without asking you for a password right. So what is the advantage of being logged in as non-root if root privs are a sudo away? Yes I just login as root (via keys)

Please if you found this post helpful or have questions.