views:

420

answers:

2

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

+1  A: 
  1. Download and Install MacPorts
  2. fire up terminal
  3. sudo port install ruby postgresql83-server rb-postgres rb-gems rb-rails
prodigitalson
I already have RoR installed, not through Macports. Wont this stuff things up?
Ganesh Shankar
nope this will use its own installation of everything completely by passing the system installation. Note though if you want to use through apache youll need to also install the port of Apach2 and then fastcgi or what have you. Then youll need to make sure you modify your path in your `~/.bash_profile` to have the macports paths before the rest of your path or else use the complete path to the installations like `/opt/local/bin/ruby` and such.
prodigitalson
Thanks for the answer. +1 as it's a good solution but I'm not sure it's exactly what I'm looking for. I want to see if I can add postgres to my existing dev environment and I feel that while macports is great, it doesn't always give you great control over versions...
Ganesh Shankar
@gshankar: To some extent this is true. Im primarly a php Dev and there was definitely a period where i had to manage my own port repo with php 5.2.x when they switch to 5.3. That hosting a local repo was alot less fuss than compiling/upgrading and hooking everything up manually. Definitely valid criticism though and im glad you found a solution that meets your need. :-)
prodigitalson
+1  A: 

I think I've managed to find a way that works. I'm borrowing heavily from this great post:

http://blog.blackwhale.at/2009/09/set-up-your-mac-for-rails-development/

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. Download PostgreSQL for Mac and start the ‘PostgreSQL for Mac’ installer in the ‘Server’ directory.
  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

    # 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 you went...

Ganesh Shankar
Dont forget to mark this as the answer.
prodigitalson
Will do! (apparently I have to wait till tomorrow) Thanks for the help :)
Ganesh Shankar
After installing i ran... sudo: /Library/PostgreSQL8/bin/createuser: command not found
AnApprentice
Hmm, have you looked in /Library/PostgreSQL8/ to see if you're actually installed in there? I just tried the command then and it works for me. Maybe you installed PostgreSQL9 ?
Ganesh Shankar