22 Jan-2014

Install PostgreSQL on Mac OSX the easy way

I have always been using PostgreSQL on Ubuntu computers; Lalely I need to install it on my Mac computer for test purposed.

I have searched on how to install PostgreSQL on my Mac computer and how to install the pg gem; and if you ever tried to do so, you will find that there are over a hundred of tutorials that show you how to do this…. in over hundred ways, that most of them don’t work for one reason or another.

I will show you here how to just do that, in the easiest way

Before I start, I want to emphasize that whatever happens do not (I repeat: DO NOT) install postgre on you Mac computer using EnterpriseDB. You will end up with thousands of installed dependancies and new user account and other useless stuff that will just multiply your boot time dramatically. And if things go south, go luck with debugging!

Just two steps:

My method of installing PostgreSQL engine on Mac OS X involves two simple steps. And I believe this is the easiest way to install it:

First: Install HomeBrew:

According to HomeBrew’s website, HomeBrew is a software package manager that installs the stuff you need, that Apple didn’t install.

To install HomeBrew on your Mac OS X, issue the following command into your terminal:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

That’s it. you have just installed HomeBrew. Not sure what to use it for? check the following step:

Second: Install PostgreSQL:

This couldn’t be any easier, and I am not sure why people are making a buzz about installing PostgreSQL engine on Mac computers while it is as simple as issuing the following command into your terminal:

# brew install postgresql

Follow the instructions at the end of the install to initialize the DB, add startup items, and start Postgres. For me, this was:

To have launchd start postgresql at login:
  ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
To load postgresql now:
  launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
  postgres -D /usr/local/var/postgres


Initially, I tried a brew install postgresql over the top of the existing version that was installed via non-Homebrew means. When it was complete, psql --version was still showing 8.4.x. I found it is best to uninstall any old PostgreSQL versions first. Of course, back up your data with pgAdmin or pg_dump.