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 --version

Choose an installation method

MethodInstallsUse it when
Homebrew libpqClient tools, including psqlYour database runs elsewhere
Postgres.appLocal server and client toolsYou want PostgreSQL running locally
PostgreSQL installerServer, pgAdmin, and command-line toolsYou 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 libpq

The 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 ~/.zshrc

Confirm the command your shell will run:

which psql
psql --version

Option 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/postgresapp

Open 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 database

Cloud 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

CommandResult
\lList databases
\c database_nameConnect to another database
\dtList tables
\d table_nameDescribe a table
\qQuit 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.