PostGIS is a powerful extension to the PostgreSQL database that adds support for geometry types and geospatial functions such as point, line, polygon, distance, area, union, intersection, etc.
PostGIS can handle large amounts of data. It is at the core of CartoDB and plays nicely with QGIS, Tilemill / Mapbox Studio and GDAL.
In this tutorial, we will see how to install PostGIS on Mac OS X. We’ll use Homebrew to install the required packages, so make sure you have Homebrew installed on your system.
To install PostgreSQL open the terminal and run the following command:
brew install postgres
You should see something like this:
By default the postgresql server will be installed under: /usr/local/var/postgres
Back in the terminal run:
brew install postgis
Once again, homebrew will inform us about the progress:
To Start the server, we will use the command line utility pg_ctl. In the terminal, run:
pg_ctl -D /usr/local/var/postgres start
Let’s check if postgres is running:
You should see something similar to:
If that’s a fresh installation, we need to initialize the database cluster:
Now we can create a new database. Let’s call it postgis_test
We’ll use the psql command line utility to connect to the database that we’ve just created:
If everything goes well, we should see the psql command prompt:
To enable PostGIS, execute the following command:
CREATE EXTENSION postgis;
If everything is OK, we should see:
Let’s check if we have PostGIS support:
To quit psql, type the following command:
By now, you should have a working postgresql server with PostGIS support enabled. Here are a few more commands that you can find useful:
pg_ctl -D /usr/local/var/postgres stop -s -m fast
Start postgresql and use a log file
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Check if postgres is installed:
brew info postgres
To drop the database run:
Delete the PostgreSQL cluster:
rm -rf /usr/local/var/postgres/
From within psql, we can use the following command to list all tables in our database:
5 thoughts on “How to install PostGIS on Mac OS X”
I am not able to create a new db. When i introduce the psql postgis_test command, ask me for a password. I’ve tried all of my passwords and still not working. ¿Any hint?
Thanks for clear and accurate instructions. After trying unsuccessfully to follow instructions in several other places, I came across your article and my installation then went smoothly.
Precise & worked perfectly well on my macOS Mojave v10.14.4
Fantastic ! Out of. the box … just be careful to remove any previous installation you had before and ifever an ERROR goes saying the cluster directory is not empty … just remove it and redo the cluster step.
Is there anyway to undo all of this?