Ryan Williams.org

The random babblings of a software developer

Fork-me

Rails 3 and PostgreSQL 9.0 on Mac OS X Snow Leopard

Getting Rails 3 to work with PostgreSQL 9.0 on Snow Leopard is pretty straight forward once you know what needs doing.

Installing PostgreSQL 9.0

I recommend using the 1 click installer of PostgreSQL available from EnterpriseDB. It makes installation very simple and will even let you automatically install addons such as PostGIS.

When that’s done you should have a PostgreSQL folder inside your Applications folder. Go ahead and launch pgAdmin from there and create a login role for your development database.

Installing the PostgreSQL Gem

You will need to install the pg gem to use PostgreSQL. So open up your Gemfile and add the line:

gem 'pg'

Unfortunately if you run bundle you will get an error when it tries to install “pg”. You will instead need to install it manually using the following command.

 sudo env ARCHFLAGS="-arch x86_64" \
  gem install pg -- \
  --with-pg-include=/Library/PostgreSQL/9.0/include/ \
  --with-pg-lib=/Library/PostgreSQL/9.0/lib/

Now run bundle to update your Gemfile.lock.

Once that’s all done you can edit your config/database.yml file and add the login role you setup previously.

Posted

Comments

mubizeg

ago, mubizeg said

Hack again?!

Russell Fulton

ago, Russell Fulton said

It works! I’ve been trying to get pg gem installed for weeks. All the other posts I found suggested setting arch to i386 - I did wonder if it should be -64…

I installed postgres 9.0.2 from source and it appears that it does not include any architecture info in the config file :(

Thanks!!!

pedaledouce

ago, pedaledouce said

i love your background !

Add Comment

If you want to add a comment, then simply fill in the form below. All fields are required.