This is ConstantOrbit's Homebrew Tap, which features formulas to help pin Postgres to 10.6 and Postgis to 2.4.
Homebrew will pull in the latest version of formulas when they are upgraded, meaning that users can inadvertently be upgraded to Postgresql >10. The postgresql.rb formula here ensures that 10.6 is installed, and the postgis.rb formulate ensures that 2.4.4 is installed.
First ensure you have upgraded to the latest homebrew:
brew update
It's recommended to go ahead and clear any existing Postgres and Postgis installations:
brew uninstall postgis --force
brew uninstall postgresql --force
brew cleanup
brew services stop postgresql
After this, install the custom brew tap:
brew tap constantorbit/homebrew-tap
Then install the latest version of Postgres and unlink it. This is done first so that we can explicitly switch to an earlier version before installing Postgis:
brew install postgresql
brew unlink postgresql
You may or may not need to nuke the data files, depending on which version(s) you already had. If you do need to do so:
rm -rf /usr/local/var/postgres
Now install Postgres from this tap with:
brew install constantorbit/tap/postgresql # yes, without the homebrew-
Now you will have both 10.6 and the latest version of Postgres installed. Switch to 10.6 with:
brew switch postgresql 10.6
Postgis 2.4 can be installed with:
brew install constantorbit/tap/postgis
Try running and accessing Postgres with the following:
brew services start postgresql
psql postgres # It should show 10.6 as the version on the prompt
After running psql postgres
, type the following in the prompt to verify your Postgis installation:
drop extension postgis; -- This might fail if it wasn't previously installed
create extension postgis; -- This should pass
select ST_Distance(
ST_GeometryFromText('POINT(-118.4079 33.9434)', 4326), -- Los Angeles (LAX)
ST_GeometryFromText('POINT(2.5559 49.0083)', 4326) -- Paris (CDG)
); -- This should print a row with 121.898285970107 as a value