Trying to get Rails up and running on my laptop under Ubuntu Breezy Badger, I ran into some serious irritation. Rails is fairly picky about which version of Ruby it will work with -- it requires either 1.8.2 or 1.8.4. Of course Breezy ships with Ruby 1.8.3. Of course.
I've always compiled Ruby from source anyway, but this time around I had been thinking I'd try doing things the simple way, and just use all the distro packages. But with the versioning weirdness, it turned out to be not so simple after all -- the only way to make things work that I could figure out was to install the Ruby packages for Dapper Drake, which of course b0rks your ability to do a normal
apt-get for everything else.
I actually even tried installing Dapper, but since it doesn't seem quite 'baked' yet (there was the little matter of my laptop not booting with the Dapper kernel), going back to building from source on Breezy seemed the most sane option for me. Here are the notes I took during the process. I they help somebody avoid some of the holes I stepped in. Do all this stuff as the superuser, natch.
First, since we're going to be building stuff from source, you have to install a compiler. I remember when I started using Ubuntu after coming from Gentoo I was aghast to see it came with nothing to compile code. We'll rectify that situation by installing gcc and friends:
apt-get install autoconf autotools-dev binutils gcc gcc-4.0 libc6-dev make
Next, since this was a brand-new install of Breezy, I had to install Apache:
apt-get install apache2 apache2-threaded-dev
Since later I intend to build mod_ruby from source, I also installed the
apache2-threaded-dev package. (In another post I'll put up how to build mod_ruby, eruby, and Ruby's DBI for database access.) Also, Rails needs mod_rewrite. Ubuntu installs it with Apache, but does not enable it. Enable it by creating a symlink for
Next, for the database. I use PostgreSQL, so I installed that, along with its dev packages so I can build the Ruby Postgres support. You'll see that step at the very end of the process. Install Postgres like so:
apt-get install postgresql postgresql-dev libpq-dev
To make Postgres work with your Ruby Web app, you have to allow conections to it over TCP/IP. You do that by setting
'tcpip_socket = true' in
/etc/postgresql/7.4/main/postgresql.conf. To make things less annoying, I also loosen the vice-like grip of Postgres security (it's a dev box, on an internal network) by setting the auth METHOD to 'trust' (from 'ident sameuser' or 'md5') in
/etc/postgresql/7.4/main/pg_hba.conf. That way I can connect with the username 'postgres' and no password.
Next, since I'm not keen on using slow CGI or WEBrick to do my dev work, I installed fcgid (an alternative to fastcgi) to run my Rails app in Apache:
apt-get install libapache2-mod-fcgid libfcgi-dev
Note that I also installed the
libfcgi-dev package so I can install the Ruby bindings for FastCGI. I'll be installing that as a Ruby gem later. Enable fcgid by creating symlinks for
Now it's time to start building stuff from source. We'll start with Ruby itself. By default it will try to stick itself in
/usr/local. The distro packages I've seen on Linux normally place it in
/usr, and that's where I like to have it too, so I build it like this:
cd ruby-1.8.4 ./configure --prefix=/usr make make install
Next, I had to install ruby-zlib, which is needed by rubygems, but not included in the core Ruby distro. I've posted on this irritation previously. Build ruby-zlib like this:
cd ruby-zlib-0.6.0 ruby extconf.rb make make install
Next, to build rubygems, which is what we'll actually use to install Rails:
cd rubygems-0.8.11 ruby setup.rb
Once rubygems is set up, you can finally install Rails itself:
gem install rails --include-dependencies
Next is the Ruby FastCGI bindings:
gem install fcgi
The very last thing to do is to build Ruby support for Postgresql, so your Rails app can talk to the database:
cd ruby-postgres-0.7.1 ruby extconf.rb --with-pgsql-include-dir=/usr/include/postgresql --with-pgsql-lib-dir=/usr/lib/postgresql make make install
Ubuntu doesn't put the Postgres libraries and development header files where the ruby-postgres default config expects to find them, so you have to tell it in the configuration step.
The very last thing you'll need to do to get your Rails app up and running is to tell it to expect fcgid instead of fastcgi. Change the line in
yourapp/public/.htaccess that looks like this:
AddHandler fastcgi-script .fcgi
And make it look like this:
AddHandler fcgid-script .fcgi
Of course you'll also want to make sure the last line in the .htaccess file points everything to
dispatch.fcgi rather than
I would love feedback on this how-to -- is there a better way to do any of this?