PostgreSQL and PostGIS installation in Mac OS.

Umesh Kafle
Oct 28, 2017 · 2 min read

PostGIS is spatial database extender for PostgreSQL object-relational database. It adds supports for geographic objects allowing location queries to be run in SQL.

When I was setting up a Rails project in my local machine it requires PostGIS setup to run the migration. I have went through their official sites and many other document to know about the installation process and found out these processes, to reinstall the PostgreSQL if another version of PostgreSQL is installed previously and installing PostGIS in Mac OS.

Remove previous versions of PostgreSQL

brew uninstall --force postgresql

Delete all Files of Postgres

rm -rf /usr/local/var/postgres

Install Postgres with Homebrew

brew install postgres

Install PostGIS with Homebrew

brew install postgis

Start PostgreSQL server

pg_ctl -D /usr/local/var/postgres start

Create Database

initdb /usr/local/var/postgres

If terminal shows an error

initdb: directory "/usr/local/var/postgres" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/usr/local/var/postgres" or run initdb
with an argument other than "/usr/local/var/postgres".

Remove old database file

rm -r /usr/local/var/postgres

Run the initdb command again

initdb /usr/local/var/postgres

Create a new database

createdb postgis_test

Enable PostGIS

psql postgis_test

This command should show the psql command prompt

psql (10.0)

type “help” for help


Creating extension for PostGIS.


If everything goes well we should see:

postgis_test=#CREATE EXTENSION postgis;



Check your PostGIS version

SELECT PostGIS_Version();

Hopefully this article will save your time .

Originally published at September 4, 2019.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade