Last Updated: July 16, 2016
· bostonaholic

Tips for installing Postgres on OS X

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.

Say Thanks

2 Responses
Add your response


Hi I had,

export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/9.5/bin"

before, would should I have now?

over 1 year ago ·

I also get

Connection to PostgreSQL - postgres@localhost [3] failed
FATAL: role "nikos" does not exist

after I tried to connect and ran initdb /usr/local/var/postgres before

over 1 year ago ·
Filed Under