Skip to content

Instantly share code, notes, and snippets.

@srt32
Last active July 18, 2021 23:43
Show Gist options
  • Save srt32/11265183 to your computer and use it in GitHub Desktop.
Save srt32/11265183 to your computer and use it in GitHub Desktop.
installing PostGIS on OSX

Installing the Postgres PostGIS extension on OSX

For reference: http://postgis.net/install

If you don’t already have PG installed

The most reliable way to get PostGIS on OSX is to download and install Postgres.app. Great for development and testing. Do not mix with other installations. Select the extension when prompted.

If you already have PG installed

You just need to add the extensions, Homebrew users can just run brew install postgis

  • Drop into your database

    psql oneblock_development

  • Run the following commands to add the extensions.

-- Enable PostGIS (includes raster)

$ CREATE EXTENSION postgis;

If you get:

ERROR:  58P01: could not open extension control file "/usr/local/Cellar/postgresql/9.3.4/share/postgresql/extension/postgis.control": No such file or directory

you probably don’t have the extension installed correctly.

-- Enable Topology

$ CREATE EXTENSION postgis_topology;

-- fuzzy matching needed for Tiger

$ CREATE EXTENSION fuzzystrmatch;

-- Enable US Tiger Geocoder

$ CREATE EXTENSION postgis_tiger_geocoder;

Confirm that it worked:

$ SELECT POSTGIS_FULL_VERSION();

You should see a message including postgis_full_version followed by a version number and some other info.

@rlburb
Copy link

rlburb commented Feb 12, 2016

If, as you say, I don't have the extension installed correctly, how do I do so? I have just installed postgis using homebrew and am encountered the error mentioned after the command "$ CREATE EXTENSION postgis;" Installing it this way is not working.

@livemixlove
Copy link

Seconding rlburb, Installed via homebrew on OSX.
I get an error after $ CREATE EXTENSION postgis;
# CREATE EXTENSION postgis; ERROR: could not open extension control file "/usr/local/Cellar/postgresql/9.4.2/share/postgresql/extension/postgis.control": No such file or directory
Any fix?

@KidA001
Copy link

KidA001 commented Jan 5, 2017

Also having the same issue that @rlblurb and @livemixlove are having with the control file not existing. Have searched around and cannot seem to solve this

@jordanmkoncz
Copy link

For anyone having the issue above, you need to install postgis using Homebrew and need to make sure the version of postgis that you install is compatible with the version of postgresql that you have already installed.

In my case I had postgresql version 9.5.5 so I needed to install postgis version 2.2.2. If you just run brew install postgis, the current version at the time of writing is 2.3.3, which is only compatible with postgresql version 9.6 and above.

I followed the instructions at http://stackoverflow.com/questions/3987683/homebrew-install-specific-version-of-formula/17757092#17757092 for how to install an older version of postgis with Homebrew. To save you some time, if you're looking to install version 2.2.2 (specifically version 2.2.2_3 which seems to be the most recent) you can use the following command:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/93fe476fc21c4a1e1ab27b1ce1f27ac4468ffa71/Formula/postgis.rb

@raywu
Copy link

raywu commented Jun 4, 2018

Thanks @jordanmkoncz. Just FYI, I'm running into this error:

lwin_geojson.c:22:10: fatal error: 'json-c/json_object_private.h' file not found

I downgraded with brew switch json-c 0.12 and got over that error.

@delongGao
Copy link

thanks @jordanmkoncz, this is the issue for my case as well. For others who may run into this in the future: if you are not sure whether your postgresql and postgis versions are compatible, don't directly do brew install postgis, this will always install the latest postgis with all the latest dependencies(can be checked here). It can cause you trouble later if you need to downgrade with all the dependencies installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment