Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install a specific version of postgresql using Homebrew that also includes bins like psql and pg_dump?

When I do brew install postgresql Homebrew currently installs v10.0. I need it to install v9.6 so I did brew install [email protected] but now there are no binaries like psql, pg_dump or pg_restore. I have the possibility to mix it up with v10.0 by just installing both versions and then just run the server in v9.6 and the binaries would be on v10.0. But I want to have everything on v9.6 for now. How can I achieve this?

like image 603
Marc Avatar asked Dec 12 '25 06:12

Marc


2 Answers

  1. Install both versions of postgresql, present brew install postgresql and legacy brew install [email protected]
  2. Uninstall both of them afterwards
  3. At /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/ you should have formulas files for both versions of postgresql, [email protected] and postgresql.rb.
  4. Open both files to edit. Copy url and sha256 values from [email protected] and overwrite with them corresponding ones in file postgresql.rb
  5. Remove folder /usr/local/var/postgres (just to clear all the leftovers from previous installations)
  6. Now install postgresql again with regular command brew install postgresql. Version 9.6 should be recognised from the edited formula file postgresql.rm and installed as latest.
  7. As a last step you can pin your version of postgresql now brew pin postgresql.

With this procedure you have postgresql 9.6 installed with working CLI commands enter image description here

like image 71
Milosz Frejnik Avatar answered Dec 15 '25 05:12

Milosz Frejnik


Versioned formulas are generally keg-only, which effectively means they are not symlinked into /usr/local. So you have them, just not automatically accessible. Homebrew should tell you that much in post-installation caveats memo (including additional manual setup options). Depending on your specific situation one of the following should work:

  1. Add the keg binaries to your PATH variable manually, e.g. export PATH="/usr/local/opt/[email protected]/bin:$PATH"
  2. Force the symlink creation with brew link [email protected] --force
  3. Use brew switch if you have/need multiple versions installed

Hope it helps.

like image 41
Ales Bukovsky Avatar answered Dec 15 '25 05:12

Ales Bukovsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!