Fix: psql: command not found (Install PostgreSQL Client)
The error fires when the shell cannot locate the psql binary — either PostgreSQL is not installed (only the server or a GUI client is), or it is installed but its bin directory is not on PATH. Fix it by installing the postgresql-client package (apt/brew), installing PostgreSQL itself (choco on Windows), or appending the bin directory to PATH.
You open a terminal — maybe to debug a Supabase connection, run a migration, or follow a tutorial — type psql and the shell answers:
$ psql
bash: psql: command not foundOn Windows PowerShell it is the same error in different words:
PS C:\> psql
psql : The term 'psql' is not recognized as the name of a cmdlet, function, script file, or operable program.The Stack Overflow canonical (Q33235968, ~700k views) is short: the PostgreSQL client is not installed, or installed but not on your shell's PATH. The two are easy to confuse — psql is a separate package on Linux and a separate Homebrew formula on macOS. Here are the exact fixes per platform.
Quick fix — install the right package#
| Platform | Command | What it installs |
|---|---|---|
| Debian / Ubuntu | sudo apt install postgresql-client | psql + libpq + pg_isready + pg_dump |
| Fedora / RHEL | sudo dnf install postgresql | client + server |
| macOS (Intel) | brew install postgresql-client | psql in /usr/local/opt/postgresql-client/bin/psql |
| macOS (Apple Silicon) | brew install postgresql-client | psql in /opt/homebrew/opt/postgresql-client/bin/psql |
| Windows (Chocolatey) | choco install postgresql | full installer, adds bin to PATH |
| Windows (manual) | EDB installer from postgresql.org | full installer, adds bin to PATH |
| Docker (any host) | docker exec -it <container> psql -U postgres | psql already inside the postgres image |
After installing, open a new terminal and run psql --version. If you see a version string, the binary is on PATH and ready.
Linux — Debian / Ubuntu / Fedora#
postgresql-client (Debian family) or postgresql (RHEL family) gives you psql, pg_dump, pg_isready, and createdb — every CLI you need to talk to a Postgres server, even if the server itself runs elsewhere (Supabase, Neon, RDS, a Docker container).
# Debian / Ubuntu
sudo apt update
sudo apt install -y postgresql-client
# Verify
psql --version
# psql (PostgreSQL) 16.xIf you want a specific major version to match a server (16.4 server ↔ 16.x client), install postgresql-client-16 instead. Mixing majors usually works but the client emits a server-version-mismatch notice on connect — annoying, not fatal.
macOS — Homebrew (Intel and Apple Silicon)#
The trap on macOS is brew install libpq. The libpq formula installs the C client library only — it does not ship the psql binary since 2022. Running psql after brew install libpq still gives "command not found".
brew install postgresql-client
which psql
# /opt/homebrew/opt/postgresql-client/bin/psql (Apple Silicon)
# /usr/local/opt/postgresql-client/bin/psql (Intel)If you want the library but also psql, you have two choices:
# Option A: install the full client (recommended)
brew install postgresql-client
# Option B: keep libpq and force-link psql into /opt/homebrew/bin
brew install libpq
brew link --force libpqFor Apple Silicon Macs, Homebrew lives at /opt/homebrew — make sure your ~/.zshrc (zsh is the default on macOS 10.15+) contains the Homebrew path:
# ~/.zshrc — only needed if Homebrew did not add it
eval "$(/opt/homebrew/bin/brew shellenv)"After editing ~/.zshrc, source ~/.zshrc or open a new terminal.
Windows — Chocolatey or EDB installer#
There are two routes on Windows. Both work; the EDB installer is the official one.
Option A — Chocolatey (fast, scripted)#
choco install postgresql -y
# psql lands in C:\Program Files\PostgreSQL\<version>\bin
# Chocolatey adds it to PATH automaticallyClose and reopen PowerShell so the new PATH loads. Then:
psql --version
# psql (PostgreSQL) 16.xOption B — EDB installer (official)#
Download from postgresql.org/download/windows and run the installer. At the component-selection step, postgreSQL client must stay checked — the server component is optional if you only want psql. The installer adds C:\Program Files\PostgreSQL\<major>\bin to your user PATH and drops a SQL Shell (psql) shortcut in the Start Menu. That shortcut opens a psql session with prompts for server, database, user, and password — works even if your PATH did not update.
Docker — psql already inside the container#
If your database runs in Docker (the official postgres image, or a Supabase local stack via supabase start), do not install psql locally just for one-off queries. The image already has it.
# Postgres container started with docker compose
docker compose up -d postgres
# Find the running container name or use the service name
docker exec -it <container_name_or_id> psql -U postgres
# or, with docker compose:
docker compose exec postgres psql -U postgresFor Supabase local dev:
supabase start
# ... wait for "API URL", "Studio URL", "DB URL" ...
# DB URL is postgresql://postgres:postgres@localhost:54322/postgres
# The studio runs at http://127.0.0.1:54323 (separate from the DB port)
docker exec -it supabase_db_<project-ref> psql -U postgresIf the image is bare (postgres:16-alpine with no entrypoint overridden), psql is at /usr/local/bin/psql — the exec path above lands you in a shell where you can run it directly.
Common mistakes#
- Installed the server, forgot the client. On Debian
postgresql(server) andpostgresql-client(CLI) are separate packages —apt install postgresqldoes not putpsqlon your path. brew install libpqand expected psql.libpqis the C library only. Runbrew install postgresql-clientfor the CLI.- Wrong PATH on Apple Silicon.
psqlis at/opt/homebrew/opt/postgresql-client/bin/psql, not/usr/local. Add/opt/homebrew/opt/postgresql-client/binto PATH or rely on Homebrew's automatic shellenv. - PATH edit did not take effect.
export PATH=...only updates the current shell. Edit~/.zshrc,~/.bashrc, or the Windows Environment Variables dialog, then open a new terminal. - Docker container is not running.
docker execfails withError: No such container— start it first withdocker compose up -d <service>orsupabase start. - Wrong container name.
docker pslists running containers; copy theNAMEScolumn exactly. Names auto-generated by compose use the project prefix. - psql is installed but version mismatches the server.
psql: server version 15.0, server version 16.4warning on connect — harmless, ignore it. Upgrade the client if you want it gone.
Official references: PostgreSQL — Client Applications (psql), PostgreSQL — Downloads, Homebrew — postgresql-client formula, Microsoft — Chocolatey postgresql package.
When pg_dump (and other tools) are not found even after installing the client#
You’ve followed the install steps above and psql --version works, but your application or tooling still fails with:
pg_dump executable was not found.
install postgresql client tools or configure 'pgsql.pgbinarydirs'.This error is specific to applications that shell out to PostgreSQL binaries — most commonly Visual Studio Code with the PostgreSQL extension, or Node.js ORM tooling like Prisma, Drizzle, or Knex when they try to call pg_dump for backup or introspection tasks. The root cause is not that the binaries are missing; it is that the calling process cannot locate them because the PATH it inherits does not include the installation directory.
On macOS, the Homebrew postgresql-client formula installs binaries into a versioned, architecture-specific path (/opt/homebrew/opt/postgresql-client/bin on Apple Silicon, /usr/local/opt/postgresql-client/bin on Intel). GUI applications started from Finder, Spotlight, or the Dock do not read your shell's ~/.zshrc or ~/.bashrc, so they launch with a minimal PATH that omits those directories entirely.
The fix: configure pgsql.pgbinarydirs#
VS Code’s PostgreSQL extension (and similar tools) accepts an explicit binary directory configuration. Open VS Code Settings (JSON), and add the path that matches your architecture:
{
"pgsql.pgbinarydirs": ["/opt/homebrew/opt/postgresql-client/bin"]
}For Intel Macs, use "/usr/local/opt/postgresql-client/bin". For Linux installations via apt or dnf, psql typically lands in /usr/bin/, which is already on the default PATH for all processes — if you see this error on Linux, confirm the binary actually exists with which pg_dump and ensure the package postgresql-client (not just postgresql) is installed.
Why this happens even when psql works in your terminal#
Your terminal is started from a shell that sources ~/.zshrc, which Homebrew’s installer modifies with the appropriate PATH entry. VS Code (and other GUI apps) are not launched from that shell; they inherit the system’s launchd environment, which has a bare-minimum PATH: typically /usr/bin:/bin:/usr/sbin:/sbin. The Homebrew prefix is absent. The pgsql.pgbinarydirs setting tells the extension exactly where to look, bypassing PATH entirely.
If you are using a different tool that throws the same error but has no equivalent config key, launch it from the terminal instead (code . from a shell that has the correct PATH, or open -a "Visual Studio Code"). If the tool is a Node.js script or CLI, ensure the process that spawns it (a terminal, a build script, or a supervisor) has loaded the full shell environment. For more on debugging connection issues once the tools are found, see the Peer Authentication Failed fix.
Related Articles#
- How to Show Tables in PostgreSQL (psql + Supabase)
- PostgreSQL DESCRIBE TABLE: The psql backslash-d Equivalent
- Fix: Peer Authentication Failed for User "postgres"
- How to Switch Database in psql
- PostgreSQL Slow Queries Fix
- Debugging Supabase RLS Issues
- Fix PostgreSQL Server Won't Start on Mac OS X (2026)
Frequently Asked Questions
One email a month — no fluff
RLS gotchas, Next.js cache debugging, and the one Supabase setting that bit me last month.
Continue Reading
How to Change a PostgreSQL User Password (Supabase)
`ALTER ROLE alice WITH PASSWORD 'newpass';` is the SQL. The psql `\password` prompt avoids logging the cleartext. In Supabase the `postgres` role password is reset from the Dashboard, not SQL. Here is each method, the scram-sha-256 default, and the three things that break after a password change.
Fix: password authentication failed for user "postgres"
The error fires when psql reaches the password prompt but the password PostgreSQL has on file does not match what you typed — common after switching auth methods, restoring from a dump, or using Docker with a baked-in password. Fix it by setting a password with ALTER USER inside psql, then verifying pg_hba.conf has scram-sha-256 (not md5 or trust) for the line matching your connection.
Fix: Peer Authentication Failed for User "postgres"
The error fires when PostgreSQL's peer auth check compares the OS username to the database role and they differ — common after sudo-ing into psql or in local dev. Fix it by matching users, or by switching the local auth method to scram-sha-256 with a real password.
Browse by Topic
Find stories that matter to you.
