Install PostgreSQL and psql

PostgreSQL 19.0

Choose the instructions for your operating system. You need a local PostgreSQL server and its command-line tools. PowerShell on Windows and Terminal on macOS or Ubuntu are enough for the lessons.

On this page

Which tools do you need?

The server and psql are the essentials. Use pg_isready to check whether the server is listening.

psql --version
pg_isready -h localhost -p 5432
PostgreSQL Server
Runs in the background, manages databases, and executes SQL.
psql
Terminal client for connecting to the server, sending SQL, and reading results.
pg_isready
Checks whether a PostgreSQL server at a given host and port accepts connections. It does not validate your password.
pgAdmin / Stack Builder
Optional. pgAdmin is a graphical client. Stack Builder installs add-ons.

Windows · EDB installer and PowerShell

Open the Windows download link in Official references and choose the EDB installer for a supported version. In Select Components, keep PostgreSQL Server and Command Line Tools. Keep the default data directory for class, set and remember the password for the database role postgres, and keep port 5432 if it is free. Skip the optional Stack Builder at the end. In a fresh PowerShell window, run the following commands.

Get-Service -Name "postgresql*"
psql --version
Get-Service -Name "postgresql*"
Lists Windows services whose names start with postgresql. Look for Running in the status column.
psql --version
Prints the installed psql client version and returns to PowerShell.

If the result differs If psql is not recognized, search Windows for Edit environment variables for your account, then open Path → Edit → New and add the installation’s bin folder. For example, use C:\Program Files\PostgreSQL\19\bin for the default version 19 location. Open a new PowerShell window and retry. If the service shows Stopped, start it from Windows Services and then check again.

macOS · Postgres.app and Terminal

Download Postgres.app from the link below, move it to Applications, open it, and click Initialize. Add its command-line tools to PATH in your current Terminal session. Keep Postgres.app running while you work.

export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"
psql --version
export PATH="…:$PATH"
Adds the Postgres.app binaries ahead of the existing PATH for this Terminal session. See the Postgres.app CLI guide below to set it up for future Terminal windows.

What to expect psql --version prints the client version. The initial PostgreSQL role is normally your macOS username.

Ubuntu · Install with apt

Run these commands in Terminal on Ubuntu. The Ubuntu repository supplies a version for your Ubuntu release.

sudo apt update
sudo apt install postgresql
sudo systemctl status postgresql --no-pager
psql --version
sudo apt update
Refreshes the package list. sudo runs the command with administrator privileges.
sudo apt install postgresql
Installs PostgreSQL and its required packages, including the client tools.
sudo systemctl status postgresql --no-pager
Shows the PostgreSQL service status without opening a scrollable pager. Use pg_isready below to check the actual connection.

If the result differs If the service is stopped on a systemd-based Ubuntu machine, sudo systemctl start postgresql starts it. On Ubuntu under WSL, make sure the service is running inside the same distribution where you run psql.

Check that the server accepts connections

Run this check in your OS terminal. Change the port if you used a different port when configuring PostgreSQL.

pg_isready -h localhost -p 5432
-h localhost
Checks the server on your own machine.
-p 5432
Checks port 5432, the usual PostgreSQL port.

What to expect localhost:5432 - accepting connections

If the result differs If you see no response, check that the server is running and that the host and port are correct. If pg_isready is not found, check the command-line tools and PATH first.

Official references