Ruby on Rails, programming, and SEO
Check out my articles about Ruby on Rails, programming, and SEO. Weekly updates? Subscribe to my feed.

Installing PostgreSQL and PostGIS on Mac OS X

How to install PostgreSQL and PostGIS on Mac OS X Lion.

So, you want to install PostgreSQL and PostGIS on Mac OS X Lion? Good idea. Here’s how to do it.

Start by downloading and installing MacPorts from

Install PostgreSQL:

$ sudo port install postgres90 postgres90-server

And follow the installation instructions. If you get a permission denied error, you can try running it using sudo -u postgres before the command itself. If you get an error message saying “Is the server running locally and accepting connections on Unix domain socket xxx?” try running it with -h localhost. This is an issue that started on Mac OS X Lion.

If you want to install a default user that will be used to login to your PostgreSQL using psql:

$ createuser -h localhost -U postgres -s <your OS X username>


$ createuser -h localhost -U postgres -s admin

Next, create a database for development. We will be using this database later on when installing PostGIS:

$ createdb -h localhost my_development_database

Install PostGIS:

$ sudo port install postgis

Install PostGIS in the database:

$ cd /opt/local/share/postgresql90/contrib/postgis-1.5/
$ psql -d my_development_database -f postgis.sql -h localhost
$ psql -d my_development_database -f spatial_ref_sys.sql -h localhost

And you’re done! You can now use PostGIS in your my_development_database database.

Related posts

Tags: , , ,


  1. [...] We will first create our geospatially enabled database. First check out out my post on installing PostgreSQL and PostGIS on Mac OS X. [...]

  2. Adrian Nye says:

    PostgreSQL 9.0 comes pre-installed on MacosX Lion,
    and is most likely already running when the macPorts version above gets installed.

  3. lassebunk says:

    Okay – Thanks for the info, Adrian.

  4. Postgres server only comes installed with Lion Server – if you’re running the desktop you’ll still need to install it.

  5. Seveners Free Board – Scientists prove Jabulani ball is ‘too perfect’…

    Installing PostgreSQL and PostGIS on Mac OS X…

Leave a comment

Fork me on GitHub