macospostgresqlpsqlmacos-sierra

Correct way to install psql without full Postgres on macOS?


Official page do not mention such case. But many users need only psql without a local database (I have it on AWS). Brew do not have psql.


Solution

  • You could also use homebrew to install libpq.

    brew install libpq
    

    This would give you psql, pg_dump and a whole bunch of other client utilities without installing Postgres.

    Unfortunately since it provides some of the same utilities as are included in the full postgresql package, brew installs it "keg-only" which means it isn't in the PATH by default. Homebrew will spit out some information on how to add it to your PATH after installation. In my case it was this:

    echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc
    

    Alternatively, you can create symlinks for the utilities you need. E.g.:

    ln -s /usr/local/Cellar/libpq/10.3/bin/psql /usr/local/bin/psql
    

    Note: used installed version instead of 10.3.

    Alternatively, you could instruct homebrew to "link all of its binaries to the PATH anyway"

     brew link --force libpq
    

    but then you'd be unable to install the postgresql package later.