Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

How to Install and Use Postgres On OS X For Ruby and Rails Development

By Peter Cooper / June 11, 2011

I hang out in #nwrug on Freenode, the IRC channel of a Ruby user group here in the UK, and floated the idea of doing a PostgreSQL (a.k.a. Postgres) installation tutorial for Ruby Inside. Coincidentally, it turned out 37signals sysadmin Will Jessop was already working on one so, I present.. Setting up PostgreSQL for Ruby on Rails development on OS X by Will Jessop :-)

The Article..

Will's post is a walkthrough of the process from sitting at an empty terminal prompt through to having a barebones Rails 3 app running on a Postgres powered database. It's entirely Mac OS X focused, so don't expect to enjoy it too much if you're on Linux or Windows!

Will covers:

  • installation (super simple with Homebrew)
  • start/stop controls for OS X
  • initialization
  • user creation
  • database setup
  • installing the pg gem

Or, the Screencast!

I still wanted to bring something to the table despite Will's work so I asked if I could make a screencast that roughly followed the same lines as his tutorial and he was up for it. So, I present, a scrappy 13 minute video alternative to the above tutorial:

My walkthrough is somewhat different. I spend a couple of minutes explaining what Postgres is, in case you're not familiar with it, and I use Mike Perham's awesome launchctl controller Lunchy to manage the starting and stopping of Postgres instead of the usual (and arcane) Apple tools. I also make references to Rebecca Black and Mister Mister.

While preparing for this post, I've found a lot of small, useful Ruby libraries that improve the Postgres experience. I'm collecting those together and will be posting with a grab-bag of useful links soon.


  1. Jared Mehle says:

    Have you come across any good GUI tools for working with Postgres? PGAdmin is pretty sad and doesn't have a native OS X look.

    Sequel Pro is my favorite DB GUI tools, but it only supports MySQL. Base is pretty good, but only supports SQLite. Navicat has tools for all of the above, but they're insanely expensive.

    There just doesn't seem to be one good tool out there for working with multiple database products.

  2. Joel Meador says:

    Very nice! First time I've tried postgres (outside of heroku), mostly because it was no hassle. Lunchy is awesome, btw. Yay, brew, bundler, and lunchy.

  3. Will Jessop says:

    @Jared I don't know of any unfortunately, I stick to the CLI. Another option could be PHPPgAdmin if you're really stuck.

  4. Worajedt S. says:

    @jared Navicat for Postgresql is native speed and good in may way of connection/reach to psql on remote side. All of the most things you need is there..

    also consider DbVisualizer (java based). If you use many db engines, dbvis is one of the app that you have to consider. Fast, Good UI, Import & Export capabilities and good sql editor inside.

    both are good for PG but dbvis is the best choice if you need multiple db engines.

  5. lobo_tuerto says:

    Same but for Ubuntu, in Spanish ;)

    Postgres on Ubuntu 11.04 for Ruby and Rails development

  6. Patrick Marsceill says:

    Followed your instructions to the letter, but am getting a permissions issue when I try to run any of the postgres commands (createuser, createdb, pgsql, etc...)

    When I get to the step where you createuser i get...

    Shall the new role be a superuser? (y/n) n
    Shall the new role be allowed to create databases? (y/n) n
    Shall the new role be allowed to create more new roles? (y/n) n
    createuser: could not connect to database postgres: could not connect to server: Permission denied
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

    any ideas? Lunchy started postgres with no errors and when I do a status, it shows the plist file as being active. Not sure what the problem could be...

  7. John says:

    Um, you know PostGreSQL is now bundled with Lion...

  8. Alessandro Dal Grande says:

    With Lion there is in fact another installation of PG. If you run the homebrew one, to get the user created etc. you need to run the right command, something like:


    Otherwise you will run PG commands with Lion configuration and you will get errors like:

    createuser: could not connect to database postgres: could not connect to server:

    No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

Other Posts to Enjoy

Twitter Mentions