Installing PostgreSQL on OSX for Rails development

前端 未结 6 1292
南笙
南笙 2021-01-30 07:30

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 metho

相关标签:
6条回答
  • 2021-01-30 07:58

    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 讨论(0)
  • 2021-01-30 07:59
    1. Download and Install MacPorts
    2. fire up terminal
    3. sudo port install ruby postgresql83-server rb-postgres rb-gems rb-rails
    0 讨论(0)
  • 2021-01-30 08:01

    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'

    0 讨论(0)
  • 2021-01-30 08:12

    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.

    0 讨论(0)
  • 2021-01-30 08:18

    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

    0 讨论(0)
  • 2021-01-30 08:21

    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/
    
    0 讨论(0)
提交回复
热议问题