Umesh Kafle
Umesh Kafle Ruby engineer with a good understand Ruby and Rails, MacOS and a lot of other things.

PostgreSQL and PostGIS installation in Mac OS

PostgreSQL and PostGIS installation in Mac OS

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

1
brew uninstall --force postgresql


Delete all Files of Postgres

1
rm -rf /usr/local/var/postgres


Install Postgres with Homebrew

1
brew install postgres


Install PostGIS with Homebrew

1
brew install postgis


Start PostgreSQL server

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


Create Database

1
initdb /usr/local/var/postgres


If terminal shows an error

1
2
3
4
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

1
rm -r /usr/local/var/postgres


Run the initdb command again

1
initdb /usr/local/var/postgres


Create a new database

1
createdb postgis_test


Enable PostGIS

1
psql postgis_test


This command should show the psql command prompt

1
2
3
4
5
psql (10.0)

type “help” for help

postgis_test=#


Creating extension for PostGIS.

1
CREATE EXTENSION postgis;

If everything goes well we should see:

1
2
3
4
5
postgis_test=#CREATE EXTENSION postgis;

CREATE EXTENSION

postgis_test=#

Check your PostGIS version

1
SELECT PostGIS_Version();

Hopefully this article will save your time .

comments powered by Disqus