34

Homebrew's current version of Postgres is 10 when installed with:

brew install postgres

How do I install an older version of postgres? Specifically 9.6

JK.
  • 493
  • 1
  • 5
  • 8

1 Answers1

53

You can find available versions to install using brew search:

$ brew search postgresql
==> Searching local taps...
postgresql        postgresql@9.4        postgresql@9.5        postgresql@9.6

To install one of these older versions, pass the full name into brew install:

$ brew install postgresql@9.6

It will give you instructions on how to add that PATH of that particular version to your bash environment, so you can use its psql etc.

If you still have psql booting up a newer version of postgresql, try this:

brew install postgres@9.6
cp -rf /usr/local/Cellar/postgresql@9.6/9.6.9 /usr/local/Cellar/postgresql/.
brew switch postgres 9.6.9
grg
  • 201,078
  • 1
    Thanks, will try that. Is 9.6 not available as a named version yet? It only has 9.4 and 9.5 listed. – JK. Oct 30 '17 at 20:41
  • 1
    As of today, 9.6 is available. – Nate Bird Nov 17 '17 at 15:35
  • Pinging @JK. for Nate's comment, have edited answer – grg Nov 17 '17 at 15:39
  • 1
    This did install, but I still have no psql commands, and libpq-fe.h library available – raarts Jan 18 '18 at 14:03
  • same here, I can't manage to find the binary to add it to the path – pgarciacamou Mar 17 '18 at 20:13
  • 1
    As of writing (1.6.1), doing brew install postgresql@9.6 seems to work, but if you attempt brew info postgresql still points to 10.3 (current stable). Doing brew info postgresql@9.6 looks like it works, but one cannot brew switch to it. Still not sure yet how one resolves that. – Scott Corscadden Apr 23 '18 at 20:05
  • Well, this MIGHT work, still getting through it: https://stackoverflow.com/a/48096389/297472 – Scott Corscadden Apr 23 '18 at 20:59
  • My work around brew install postgres@9.6; cp -rf /usr/local/Cellar/postgresql@9.6/9.6.9 /usr/local/Cellar/postgresql/.; brew switch postgres 9.6.9 – marneborn Jun 07 '18 at 22:35
  • 1
    @Adi Thanks for your edit, though I’m not sure I fully understand it. Can you explain a little more about why that works? Could a symlink be used instead of copying the files? – grg Oct 05 '18 at 07:58
  • @marneborn Your comment was edited into my answer by Adi, perhaps you can help answer the questions in my comment above? – grg Oct 05 '18 at 07:59
  • brew switch is the "old way" to handle versions, these days it's by leaving it there and modifying your PATH, see the instructions after installation of a particular version... – rogerdpack Aug 15 '19 at 19:39
  • At the end I had to also run rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8 – marcelosalloum Sep 16 '20 at 17:35