Install PostgreSQL server and client tools on macOS, Linux, or Windows so you can create databases and run SQL.
Use your operating system’s package manager. Homebrew on macOS, APT on Ubuntu/Debian, YUM/DNF on RHEL/CentOS/Fedora, and the interactive installer on Windows give you the shortest path from zero to a running database.
brew install postgresql
. Homebrew downloads the latest stable version, compiles if needed, and registers the service. Start it with brew services start postgresql
, then verify with psql -V
.Add the official PostgreSQL APT repo for newer versions:
sudo apt update
sudo apt install curl ca-certificates gnupg
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/pg.asc
echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt update
sudo apt install postgresql-16
The service starts automatically. Test with sudo -u postgres psql -c "SELECT version();"
.
Enable the PostgreSQL repository, then install:
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-$(rpm -E %rhel)-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo dnf -qy module disable postgresql
sudo dnf install -y postgresql16-server
sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
sudo systemctl enable --now postgresql-16
Confirm with psql --version
.
Download the EnterpriseDB installer, run it, choose components (server, pgAdmin, command-line tools), set a superuser password, port (5432), and locale. After installation, open psql
from the Start Menu or connect using pgAdmin.
Default port is 5432
. A system user and database role named postgres
is created. Data lives in /usr/local/var/postgres
(macOS), /var/lib/postgresql/<version>/main
(Debian/Ubuntu), or /var/lib/pgsql/16/data
(RHEL-based).
psql -h localhost -U postgres
If ident/peer auth is enabled, omit -U
and connect as the OS user.
Homebrew runs brew services start postgresql
. Systemd systems use systemctl enable --now postgresql
(or postgresql-16
if multiple versions). Windows installs a background service automatically.
createuser --interactive --pwprompt dev
).pg_dump
and pg_basebackup
regularly.shared_buffers
, work_mem
, and WAL settings to match RAM and workload.# macOS
brew install postgresql
# Ubuntu/Debian (default repo)
sudo apt update && sudo apt install postgresql
# RHEL/CentOS (default repo)
sudo dnf install postgresql-server
sudo postgresql-setup --initdb
# Windows (PowerShell winget)
winget install PostgreSQL.PostgreSQL
Check the service status: systemctl status postgresql
or brew services list
. Then run psql -c "SELECT version();"
; you should see server and client versions.
Yes. Use version-specific packages (e.g., postgresql-15
, postgresql-16
) or Homebrew’s brew install postgresql@15
. Bind each instance to a different port.
Every installer creates a role named postgres
with superuser privileges. Protect its password or disable remote login.
Stop the service, remove packages (brew uninstall postgresql
or sudo apt purge postgresql*
), then delete the data directory. Backup before removal.