开发者

Installing PostgreSQL on OSX for Rails development

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


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.


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'


Old question, but still maybe i can help someone with this (rather simple) solution:

gem install pg -- --with-opt-include=/opt/local/include/postgresql84/ --with-opt-lib=/opt/local/lib/postgresql84/


  1. Download and Install MacPorts
  2. fire up terminal
  3. sudo port install ruby postgresql83-server rb-postgres rb-gems rb-rails


Thanks to Ganesh for the good awnser, my sudo url looked a bit diffirent :) here is what I have
sudo -u postgres /Library/PostgreSQL/9.2/bin/createuser


Ryan Bate's Railscast on PostgreSQL walks you through setting it up on a Mac with Homebrew. Very easy, worked for me on OSX 10.6.8.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜