Agile software development using Kanban & Scrum. We code Flex & Ruby on Rails in Auckland, New Zealand.

  • Install pg gem via Bundler on OSX Snow Leopard

    I encountered three problems installing the Postgres ruby gem (pg) when using Bundler to install all the gems for a project on my OSX Snow Leopard 10.6 machine.

    Firstly, the gem fails to build on Snow Leopard when you use the binary version of Postgres that is distributed by Enterprise DB. To work around this, the Postgres binaires need to be installed using Mac Ports.

    Secondly, the pg gem must be installed using additional bash environment variables.

    Thirdly, every time you run bundle install, the current version of Bundler hard re-installs all gems listed in ./Gemfile. This means that even if you install the pg gem correctly by hand, bundler will still try to reinstall it.

    All three are resolved as below, in my case I am using Postgres 8.4.

    Install postgres from Mac Ports

    sudo port install postgres84
    

    Include the postgres binaries in the PATH environment variable

    export PATH=/opt/local/lib/postgresql84/bin:${PATH}
    

    Then run bundle install with the all-important arch flag

    env ARCHFLAGS="-arch x86_64" bundle install
    

    Edit: removed sudo from bundle command.