Install psql on Mac
Ghazi · Updated July 28, 2026
The shortest route is Homebrew: install libpq, add its binary directory to your PATH, and check the version. Use Postgres.app instead when you also want a local PostgreSQL server.
brew install libpq
echo 'export PATH="$(brew --prefix libpq)/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
psql --versionChoose an installation method
| Method | Installs | Use it when |
|---|---|---|
| Homebrew libpq | Client tools, including psql | Your database runs elsewhere |
| Postgres.app | Local server and client tools | You want PostgreSQL running locally |
| PostgreSQL installer | Server, pgAdmin, and command-line tools | You want the full packaged installation |
Option 1: Homebrew libpq
Homebrew's libpq formula installs the PostgreSQL client library and command-line tools without setting up a PostgreSQL server service.
brew install libpqThe formula is keg-only, so its binaries may not be on your shell path. Add the directory to zsh:
echo 'export PATH="$(brew --prefix libpq)/bin:$PATH"' >> ~/.zshrc
source ~/.zshrcConfirm the command your shell will run:
which psql
psql --versionOption 2: Postgres.app
Postgres.app runs a local PostgreSQL server and includes psql. Move the app to Applications, initialize a server, then add its command-line tools to macOS's system path:
sudo mkdir -p /etc/paths.d
echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresappOpen a new Terminal window and run psql --version. The command above follows Postgres.app's current installation documentation.
Option 3: PostgreSQL installer
PostgreSQL.org links to a macOS installer distributed by EDB. It includes the server, pgAdmin, Stack Builder, and command-line tools. This is the largest option, but it keeps the server and administration tooling in one installer.
Connect with psql
Use a PostgreSQL connection string:
psql "postgresql://user:password@localhost:5432/database"Or pass the connection fields separately:
psql -h localhost -p 5432 -U user -d databaseCloud providers often require SSL. Use the exact connection string supplied by the provider rather than rebuilding it from memory.
Fix common Mac errors
zsh: command not found: psql
Check brew --prefix libpq and echo $PATH. If you just changed ~/.zshrc, run source ~/.zshrc or open a new Terminal window.
connection refused
psql is installed, but no server answered at the host and port. Start the local server, publish the Docker port, or check the cloud connection settings.
password authentication failed
The server answered, but rejected the credentials. Check the user, password, database name, and provider SSL requirements.
Useful commands after installation
| Command | Result |
|---|---|
\l | List databases |
\c database_name | Connect to another database |
\dt | List tables |
\d table_name | Describe a table |
\q | Quit psql |
When a GUI is easier
Keep psql for scripts, SSH sessions, and repeatable commands. Use a GUI when you need to scan a wide result, browse tables, edit one row, inspect JSON, or keep several queries open.
See the psql GUI guide or read the full psql and PostgreSQL GUI comparison.