How to Install psql (PostgreSQL CLI) in PostgreSQL

Galaxy Glossary

How do I install the PostgreSQL CLI (psql) on macOS, Windows, or Linux?

Install the standalone PostgreSQL command-line client (psql) on macOS, Windows, and Linux without deploying the full database server.

Sign up for the latest in SQL knowledge from the Galaxy Team!

Description

Why install only the PostgreSQL client?

The psql CLI lets you connect to remote PostgreSQL servers, run SQL, and automate tasks without running a local database. This saves resources on developer machines and CI pipelines.

Which package do I need?

Most systems split PostgreSQL into server and client packages. Look for names like postgresql-client, postgresqlXX-client, or libpq. Installing these pulls in psql and supporting libraries only.

How to install on macOS?

Use Homebrew for the fastest setup:

$ brew install postgresql

Homebrew bundles both client and server. Skip brew services start postgresql if you only need the client.

How to install on Ubuntu/Debian?

$ sudo apt-get update
$ sudo apt-get install postgresql-client

Add a major-version suffix (e.g., postgresql-client-15) to match your production version.

How to install on RHEL/CentOS/Fedora?

$ sudo dnf install postgresql
# or specific version
$ sudo dnf install postgresql15

Older systems use yum instead of dnf.

How to install on Windows?

Download the "psql Client only" option from EDB installers or install via chocolatey:

PS> choco install postgresql

During the GUI installer, uncheck "Stack Builder" if you don’t need extras.

How do I verify the installation?

$ psql --version
psql (PostgreSQL) 15.3

A version string confirms psql is on your PATH.

What is the basic connection command?

$ psql -h db.example.com -U app_user -d app_db -p 5432

The -W flag prompts for a password interactively.

Best practices after installation?

Store connection parameters in ~/.pgpass or environment variables to avoid exposing passwords in shell history. Use psqlrc for prompt and output tweaks.

Can I uninstall the server safely?

Yes. Removing postgresql server packages will not affect libpq or psql when installed separately.

Common troubleshooting questions

See the FAQ section below for PATH issues, SSL errors, and version mismatches.

Why How to Install psql (PostgreSQL CLI) in PostgreSQL is important

How to Install psql (PostgreSQL CLI) in PostgreSQL Example Usage


psql -h 10.0.0.5 -U analytics -d sales -c "SELECT COUNT(*) FROM orders;"

How to Install psql (PostgreSQL CLI) in PostgreSQL Syntax


macOS:   brew install postgresql
Ubuntu:  sudo apt-get install postgresql-client[-<version>]
RHEL:    sudo dnf install postgresql[<version>]
Windows: choco install postgresql or EDB "psql Client only" installer

Common Mistakes

Frequently Asked Questions (FAQs)

Why does my shell say “psql: command not found”?

The installer didn’t add psql to your PATH. Re-open your terminal or add /usr/pgsql-XX/bin (Linux) or C:\Program Files\PostgreSQL\15\bin (Windows) to PATH.

Can I connect to Amazon RDS or Neon with this client?

Yes. psql works with any PostgreSQL-compatible host. Supply the hostname, port, user, and database exactly as provided by the cloud provider.

Is it safe to script passwords with -W?

Use ~/.pgpass (600 permissions) or PGPASSWORD environment variable in CI. Avoid plain text in shell history.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo