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.
- 
        For those on MacPorts, here's what I did: superuser.com/questions/305031/…sudo– sudo2019-09-01 20:04:54 +00:00Commented Sep 1, 2019 at 20:04
 - 
        16@Ssswift It doesn't say there isn't a way, just doesn't say there is a way.sudo– sudo2019-09-01 20:05:24 +00:00Commented Sep 1, 2019 at 20:05
 - 
        Congratulations! The wiki now links to your question. wiki.postgresql.org/wiki/Homebrewmysteryegg– mysteryegg2025-04-21 15:37:05 +00:00Commented Apr 21 at 15:37
 
9 Answers
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:
# if using Apple Silicon (M1 or later)
echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc
# if using Intel x64
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc
Alternatively, you can create symlinks for the utilities you need. E.g.:
ln -s /opt/homebrew/opt/libpq/bin/psql /opt/homebrew/bin/
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.
13 Comments
brew link --force libpq but that will create a bunch of other symlinks you may not want/need.ln -s /usr/local/Cellar/libpq/11.3/bin/psql /usr/local/bin/psql / ln -s /usr/local/Cellar/libpq/11.3/bin/pg_dump /usr/local/bin/pg_dump / ln -s /usr/local/Cellar/libpq/11.3/bin/pg_restore /usr/local/bin/pg_restorefor cmd in psql pg_dump pg_restore; do ln -s ../opt/libpq/bin/$cmd /usr/local/bin/$cmd; doneecho 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrcsudo ln -s $(brew --prefix)/opt/libpq/bin/psql /usr/local/bin/psql. Repeat for others, like pg_dump. And @SametBaskıcı -- I prefer symlinks so other non-terminal tools can use it (like Intellij DB connector with pg_dump).libpq 11.2
MacOS & zsh or bash
below works
- install 
libpq 
brew install libpq
update PATH
if use zsh:
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc source ~/.zshrc # or on M1 MacOS echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc source ~/.zshrcif use bash:
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile source ~/.bash_profile
5 Comments
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile if you're using bash./opt/homebrew/opt/libpq/bin on M1 processorIf you truly don't need postgresql then you don't even have to alter your path to use libra, just link libpq. The docs say the only reason it isn't is to avoid conflicts with the PostgreSQL package.
brew uninstall postgresql
brew install libpq
brew link --force libpq
    1 Comment
Homebrew only really has the postgres formula, and doesn't have any specific formula that only installs the psql tool.
So the "correct way" to get the psql application is indeed to install the postgres formula, and you'll see toward the bottom of the "caveats" section that it doesn't actually run the database, it just puts the files on your system:
$  brew install postgres
==> Downloading https://homebrew.bintray.com/bottles/postgresql-9.6.5.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring postgresql-9.6.5.sierra.bottle.tar.gz
==> /usr/local/Cellar/postgresql/9.6.5/bin/initdb /usr/local/var/postgres
==> Caveats
<snip>
To have launchd start postgresql now and restart at login:
  brew services start postgresql
Or, if you don't want/need a background service you can just run:
  pg_ctl -D /usr/local/var/postgres start
==> Summary
🍺  /usr/local/Cellar/postgresql/9.6.5: 3,269 files, 36.7MB
Now you can use psql to connect to remote Postgres servers, and won't be running a local one, although you could if you really wanted to.
To verify that the local postgres daemon isn't running, check your installed homebrew services:
$ brew services list
Name       Status  User Plist
mysql      stopped      
postgresql stopped      
If you don't have Homebrew Services installed, just
$ brew tap homebrew/services
...and you'll get this functionality. For more information on Homebrew Services, read this excellent blog post that explains how it works.
3 Comments
brew link step. Forcing the link with libpq is necessary due to the keg_only declaration in the formula. Given this specific complication, I stand by this answer as being the "correct" way to do what the question asks. I recognize that many users will still prefer the libpq approach though.Install libpq:
 brew install libpq
Then, create a symlink:
sudo ln -s $(brew --prefix)/opt/libpq/bin/psql /usr/local/bin/psql
Hope it helps.
Found so many useful answers here, but a bit outdated since homebrew moved the installation files to /opt/homebrew/Cellar/libpq/15.1. After libpq is installed with brew install libpq you can run below command to see new location
brew link --force libpq
Then you can add it to your zshrc with
echo 'export PATH="/opt/homebrew/Cellar/libpq/15.1/bin:$PATH"' >> ~/.zshrc
    Comments
Binaries courtesy of EnterpriseDB
I found all of these really unsatisfying, especially if you have to support multiple versions of postgres. A MUCH easier solution is to download the binaries here:
https://www.enterprisedb.com/download-postgresql-binaries
And simply run the executable version of psql that matches the database you're working against without any extra steps.
example:
./path/to/specific/version/bin/psql -c '\x' -c 'SELECT * FROM foo;'
    2 Comments
A little late, but really the simpliest way is only to:
brew install libpq
It should, automatically add the libpq binaries (which include psql) in /opt/homebrew/opt/libpq/bin. This path might is not in your PATH environment variable. In my case, my regular terminal (that I do not use) has it but Warp (that I do use) did not. To fix this, the libpq binary path needs to be added to your PATH environment variable. To do so, the following line has to be added to the shell configuration file :
export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
Example for the shell configuration file being .zshrc
echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
To check it, run : psql
Comments
You could try brew install postgresql
But this provides a nice GUI to manage your databases https://postgresapp.com
4 Comments
brew install postgresql install psql with database itself :(psql, but, as a bonus, you don't have to mess with the PATH or symlinks...