Skip to content

Instantly share code, notes, and snippets.

@jonathandean
Last active December 8, 2021 19:15
Show Gist options
  • Save jonathandean/7449772 to your computer and use it in GitHub Desktop.
Save jonathandean/7449772 to your computer and use it in GitHub Desktop.
Installing postgres gem pointing to homebrew installation

I needed to reinstall my postgres gem after upgrading to OS X Mavericks. I used homebrew to install postgres.

Find the path to your postgres config with

brew info postgres

And look for something like: postgres -D /usr/local/var/postgres # serve that database

Now use the --with-pg-config option to point to that directory and use gem install directly instead of bundler for just this one:

gem install pg -- --with-pg-config=/usr/local/var/postgres

If using Postgres.app:

gem install pg -- --/Applications/Postgres93.app/Contents/MacOS/bin/pg_config

Optionally, with a version number:

gem install pg -v '0.17.0' -- --with-pg-config=/usr/local/var/postgres

Now you should be able to do bundle install again.

Edit: Even better, you should set this in your bundler config so that each time you install the pg gem it will use those build arguments:

bundle config build.pg --with-pg-config=/usr/local/var/postgres

or for Postgres.app:

bundle config build.pg --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config

Now you can just use bundle install normally.

I did not have to remove the old version of the pg gem first, it worked well enough installing over the old one.

I also couldn't use the socket to connect anymore and instead was getting an error like this when starting Rails:

could not connect to server: No such file or directory (PG::ConnectionBad)
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

I got it working by changing my config/database.yml to use a hostname and port by adding the lines:

host: localhost
port: 5432

I have no idea why it doesn't create the socket connection anymore. It could have something to do with also upgrading my postgres version to 9.3, which I probably didn't need to do. I was lost for a while and that was one of the many things I did that I wish I hadn't...

If you need help with your database.yml this may help: https://gist.github.com/erichurst/961978

@ziaulrehman40
Copy link

And for linux?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment