Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing PostgreSQL on OSX for Rails development

Tags:

I've spent several hours over the past few days trying to get PostgreSQL to play nice with RoR on my Mac.

I've followed several tutorials using several different methods such as installing PostgreSQL manually and installing from various 1-click installers

However the all the different methods I tried failed on the last step of installing the pg gem. Very frustrating!

Does anyone here have a tried and tested tutorial for getting this done? (Or would you like to write some instructions here...?)

My environment is this: Macbook running OSX 10.6, PostgreSQL 8.4.1 server

like image 518
Ganesh Shankar Avatar asked Feb 16 '10 06:02

Ganesh Shankar


2 Answers

I think I've managed to find a way that works. I'm borrowing heavily from this great post1, but since they are installing a bunch of other stuff at the same time I'm going to write out what I did here for people who are just looking for the PostgreSQL install answer.

1 Editor's note: Link seemed dead when I tried. Is this the one? http://blog.blackwhale.at/?p=175#PostgreSQL Please fix if it is.

  1. Download PostgreSQL for Mac and download the ‘Postgres.app’ installer.

  2. Create a user for your rails development (keep in mind that if you're sharing an application during development you'll probably want the same user between all members your dev team in order to avoid headaches)

    sudo -u postgres /Library/PostgreSQL8/bin/createuser
    
  3. Enter your Mac OS X system user name as role name, and make it a superuser.

  4. Install the pg gem so Rails can talk to PostgreSQL

    sudo env PATH=/Library/PostgreSQL8/bin:$PATH gem install pg
    
  5. Configure your rails app to talk to PostgreSQL. You can either create a new application with:

    rails *appname* -d postgresql (for Rails 3 -> rails new *appname* -d postgresql)
    

    Or for an existing app, modify your database.yml file.

This worked for me without any hiccups. If anyone else tries using this method I'd be interested to hear some feedback on how it went for you.

like image 71
Ganesh Shankar Avatar answered Sep 29 '22 21:09

Ganesh Shankar


On a 64-bit Mac (Snow Leopard with Core 2 Duo or newer) I had to compile PostgreSQL from source, as rails kept complaining that:

*** Your PostgreSQL installation doesn't seem to have an architecture in common
with the running ruby interpreter (["ppc", "i386", "x86_64"] vs. [])

The architecture mismatch was probably bc I'd compiled rails from source, which defaulted to 64-bit. The binary installer on postgresql.org seemed only a 32-bit version. Setting ARCHFLAGS didn't fix this for me.

Anyhow, if you download the [source][1] from postgresql.org and follow the instructions in the INSTALL file, it's fairly straightforward. You don't have to create a new user if you use your own account. I did have to create the sysctl.conf file to expand shared memory - just google 'postgresql os x sysctl.conf'

like image 25
Tyler Avatar answered Sep 29 '22 23:09

Tyler