Using Postgresql with Rails 3.1: the 'pg' gem

October 17, 2011


This post was originally published in the Rambling Labs Blog on October 17, 2011.


As you may know I’ve been learning Ruby on Rails for the last few weeks. I’m also currently developing an application using the edge version of RefineryCMS (which is really a Rails 3.1 application), integrated with the almighty Heroku.

I wanted to use RefineryCMS with Postgresql, so the only thing that I had to do was installing postgresql and it’s corresponding gem ‘pg’… Or so I thought.

I wasn’t surprised. About a year ago I had the same unfulfilled expectations with mysql and the mysql gem. So, this is what I had to do:

  • First, of course, install postgresql with apt-get install postgresql
  • Then, install the libpq-dev with apt-get install libpq-dev. Note that it’s “pq” and not “pg” as you would probably expect.
  • Finally, install the “pg” gem with gem install pg

With that done, you should be ready to go. :) Enjoy!