As there are two ways to solve this question, I asked for another approach here.

Whenever a major release of PostgreSQL appears, homebrew will happily install it right away, unless one pins a certain version or installs a specific version from Homebrew/core.

So far so good, but the problem is that PostGIS also keeps updating and eventually will be incompatible with pinned or Homebrew/core versions of PostgreSQL. Again, one can pin PostGIS, yet Homebrew/core does not offer previous versions. From time to time I do brew cleanup and somehow I am now left with a broken PostGIS database. Ok, so "time to jump to PostgreSQL 10.1", I though, but pg_upgrade now gets stuck with the error

ERROR: could not access file "$libdir/postgis-2.3": No such file or directory

That means I can't back nor forth: I cannot figure out how to get PostGIS working with [email protected] and I cannot pg_upgrade to the new version of PostgreSQL (10.1).

Therefore my question can be answered in two ways. Here I am asking:

How to install PostGIS with older PostgreSQL versions, i.e. [email protected], using homebrew?

The second approach is described at Upgrading PostgreSQL with broken PostGIS installation ("$libdir/postgis-2.3" error)?

Tried so far:

  • This gist offers a solution and it might actually work. However, I had to use ln -s instead of cp -a. It seems to be working now, but unfortunately I have the problem that my database is already on 2.4 and there seems to be no downgrade path. Will keep trying.
  • Using PostGIS can certainly be a GIS topic, but trying to defeat installation/upgrade tools seems more like an OS task, unrelated to our charter.
    – Vince
    Commented Nov 12, 2017 at 12:48
  • 3
    @Vince Funny you say that. I keep getting such comments here, although GIS SE is full with such questions. There is even a homebrew tag. Anyway, please move it if you think this is appropriate.
    – n1000
    Commented Nov 12, 2017 at 12:58
  • P.S.: Just added the installation tag as well... @Vince
    – n1000
    Commented Nov 12, 2017 at 13:02
  • 1
    To the people in favor of closing the question, please participate in the discussion if installation-related questions are on-topic. Dear downvoters, please give me an indication how to improve my question!
    – n1000
    Commented Nov 12, 2017 at 20:25
  • 2
    This worked like a charm for me, installing Postgres 9.6.10 and PostGIS 2.4: github.com/CloverHealth/homebrew-tap
    – KenH
    Commented Dec 30, 2018 at 20:26