Installing PostgreSQL on Mac OS X

Here is what I did to get PostgreSQL and the pg ruby gem installed on Mac OS X Leopard. This post is more for my personal reference, but if anyone finds it useful, so be it. There are other posts around that deal with the same issue, but I’ve not found one that has the complete picture.

Prerequisites

I’m using the Ruby and RubyGems that come installed with Leopard.

You will need to install the following first:

Installing PostgreSQL

Install PostgreSQL from MacPorts using the following command in your Terminal:

sudo port install postgresql84 postgresql84-server

Make sure to follow the instructions printed at the end of the installation, so that you can set up PostgreSQL to start automatically.

Installing pg Gem

Update: The “pg” gem is considered the most current of those that provide a PostgreSQL access layer. I previously mentioned the “postgres” gem.

This is the part that might trip you up if you try the standard gem install pg route. There are two ways to ensure that this works.

The first is to ensure that the directory containing PostgreSQL executables (notably pg_config) is in your PATH. You can add the following to /etc/profile:

export PATH=/opt/local/lib/postgresql84/bin:$PATH

Then run sudo gem install pg as usual.

If you do not modify your PATH, use the following in your Terminal instead so that the PostgreSQL headers and libraries are found:

sudo env ARCHFLAGS="-arch i386"
  gem install pg --
  --with-pgsql-include=/opt/local/include/postgresql84
  --with-pgsql-lib=/opt/local/lib/postgresql84

Update: On Mac OS X 10.6 Snow Leopard, you may need to use “x86_64″ instead of “i386″ in the above command.

I hope that’s the full story…

This entry was posted in Code and tagged , . Bookmark the permalink.

2 Responses to Installing PostgreSQL on Mac OS X

  1. rbarriga says:

    a minor fix postgres 8.4 binary distribution for osx

    sudo env ARCHFLAGS=”-arch i386″
    gem install postgres —
    –with-pgsql-include=/Library/PostgreSQL/8.4/include
    –with-pgsql-lib=/Library/PostgreSQL/8.4/lib

  2. pete says:

    I’ve updated my post – the “pg” gem is the most current of the PostgreSQL gems.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>