Tips for installing Postgres on OS X

Posted on

Tips for installing Postgres on OS X

Here’s a gist I wrote to help with installing postgres on OS X.

1) you must first uninstall the ‘pg’ gem if you have it installed already.

gem uninstall pg or bundle exec gem uninstall pg in the context of a project (rails, sinatra, anything with a Gemfile).

2) Install postgres with homebrew.

brew install postgres

3) Add /usr/local/bin to the head of your $PATH to ensure the homebrew version of postgres is used.

Add this to your .bashrc or .zshrc depending on your preferred shell.


4) Create a database for your system to use. Your current user will be the owner.

initdb /usr/local/var/postgres

If one already exists, remove it with rm -rf /usr/local/var/postgres and try the command above again.

5) Create a LaunchAgent to start postgres on boot.

Your postgres version below may be different. Adjust the path for your system.

cp /usr/local/Cellar/postgresql/9.2.2/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents

If you notice another postgres LaunchAgent in ~/Library/LaunchAgents/ you should remove it.

6) Load the LaunchAgent via launchctl.

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

7) Finally, reinstall the ‘pg’ gem.

gem install pg or bundle install

I hope this helps!

Please comment or submit changes.

Leave a Reply

Your email address will not be published.