Tuesday, July 28, 2009

Rails/Postgres Setup Gotchas - Ubuntu 9.04

I recently switched to Ubuntu 9.04 after using OpenSUSE- and Fedora-Based development environments for several years, and it's been great for both Rails development and general use. The defaults are well-chosen, hardware integration is seamless, and in general, the user experience is the best I've seen of any Linux distro. Still, the default Ubuntu install is missing many important development packages; I had to take a few unexpected steps to get a simple, Postgres-backed Rails project running under Ruby 1.8. Hopefully, documenting these steps will save time for other developers.

First, install basic ruby and rubygems packages:

$ sudo apt-get install ruby ruby-dev rubygems

If your app needs to make requests over SSL, i
nstall Ruby OpenSSL bindings:
$ sudo apt-get install libopenssl-ruby

Install basic postgres packages. Note that some applications won't require postgresql-contrib:
$ sudo apt-get install postgresql postgresql-8.3 postgresql-8.3-plr
postgresql-client-8.3 postgresql-client-common postgresql-common
postgresql-contrib postgresql-contrib-8.3 postgresql-server-dev-8.3

Install the postgres gem (tested w/ version
$ sudo gem install postgres

Initialize postgres. As your system's postgres user:
$ initdb -D /var/lib/pgsql/data
$ pg_ctl -D /var/lib/pgsql/data -l logfile start

Make sure postgres starts on boot. In Ubuntu, this should be done automatically for you, but just to be sure:
$ sudo update-rc.d postgresql-8.3 defaults
# System startup links for /etc/init.d/postgresql-8.3 already exist

As the postgres user, create a user for psql; answering no to all questions. This will probably be the user referenced in your database.yml config file.
$ createuser dbuser

In order to give the user privilages to run DROP DATABASE for commands like
rake:test, you may have to do the following in psql:

No comments: