PostgreSQLInstalling PostgreSQL

Installing PostgreSQL

Before you can run any of the examples in this series, you need a working PostgreSQL server. The steps differ slightly by operating system, but the end result is the same: a running postgres process listening for connections, plus the psql command-line client to talk to it.
Windows
The most common way to install PostgreSQL on Windows is the official interactive installer, distributed via EnterpriseDB. It bundles the server, psql, pgAdmin (a graphical admin tool covered later in this series), and Stack Builder, a utility for optionally installing extra drivers and extensions after setup.
  • Download the installer from the official PostgreSQL downloads page

  • Run it and choose which components to install (keep the defaults if unsure)

  • Set a password for the default postgres superuser when prompted

  • Keep the default port, 5432, unless you have a specific reason to change it

  • Optionally launch Stack Builder at the end to add extensions

macOS
On macOS, the fastest route is Homebrew. Alternatively, Postgres.app gives you a menu-bar application that starts and stops a full PostgreSQL server with no terminal commands required.

Installing with Homebrew

Bash
brew install postgresql@16
brew services start postgresql@16
Linux

Most Linux distributions ship PostgreSQL through their standard package manager.

Debian / Ubuntu (apt)

Bash
sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl enable --now postgresql

Fedora / RHEL (dnf)

Bash
sudo dnf install postgresql-server postgresql-contrib
sudo postgresql-setup --initdb
sudo systemctl enable --now postgresql
Verifying your installation

Whatever platform you used, confirm the client tools were installed correctly by checking the version:

Bash
psql --version
On Linux and macOS, the installer typically creates an operating system user called postgres along with a matching database superuser of the same name. On Windows, you set the postgres superuser password directly during setup. Either way, you should now be able to connect:

Bash
psql -U postgres
The quick cross-platform alternative: Docker

If you already use Docker, running PostgreSQL in a container avoids touching your operating system at all, and is trivial to tear down and recreate:

Running PostgreSQL in Docker

Bash
docker run --name pg-tutorial \
  -e POSTGRES_PASSWORD=mysecretpassword \
  -p 5432:5432 \
  -d postgres
Which version should I install?
Unless you have a specific requirement, install the latest stable major version. PostgreSQL maintains each major version for five years, and the SQL you learn in this series works the same way across recent versions.
Tip
Whichever method you choose, jot down the port (default 5432), the superuser name (usually postgres), and the password you set — you will need all three on the next page to connect with psql.