Installation Basics
8 examples for installing PostgreSQL 18 on common platforms - 6 basic and 2 intermediate.
Prerequisites
# Verify you have sudo or root for package installs
uname -a- Target PostgreSQL 18.4 (stable 18) or the current minor of your supported major.
- Prefer official packages over source builds unless you need custom compile flags.
- Run the database OS user as a dedicated
postgresaccount, never as root.
Basic Examples
1. Check Installed Version
Confirm what is already on the host before changing anything.
psql --version
postgres --versionpsqlis the client;postgresis the server binary.- Major version must match across client and server for
pg_dumprestores. - Cloud managed instances hide the binary - use
SELECT version();instead.
Related: initdb & Data Directory - first cluster setup
2. Install on Debian/Ubuntu
Use the PGDG apt repository for current majors.
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
sudo apt update
sudo apt install -y postgresql-18 postgresql-client-18- PGDG tracks releases faster than distro default packages.
postgresql-18creates a cluster viainitdbautomatically on Debian-family systems.- Pin the major in automation - do not rely on
postgresqlmetapackage alone.
3. Install on RHEL/Rocky/Alma
Enable the PGDG yum repo and install the server package.
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo dnf -qy module disable postgresql
sudo dnf install -y postgresql18-server postgresql18
sudo /usr/pgsql-18/bin/postgresql-18-setup initdb
sudo systemctl enable --now postgresql-18- Disable the stock
postgresqlmodule to avoid version conflicts. postgresql-18-setup initdbcreatesPGDATAunder/var/lib/pgsql/18/data.- Enable systemd unit at boot for production hosts.
Related: Systemd & Service Management - start/stop/reload
4. Install on macOS (Homebrew)
Fast local dev installs on Apple Silicon or Intel Macs.
brew install postgresql@18
brew services start postgresql@18
echo 'export PATH="/opt/homebrew/opt/postgresql@18/bin:$PATH"' >> ~/.zshrc- Homebrew does not create a
postgressystem user - your macOS user owns the data dir. - Add the keg-only bin path to
PATHforpsqlandinitdb. - Fine for development; use packages or containers for production parity.
5. Verify Server Is Running
Connect locally and read the catalog version.
SELECT version();
SHOW server_version;
SHOW data_directory;server_versionis the numeric GUC;version()includes build flags.data_directoryconfirms whichPGDATAthis instance uses.- If connection fails, check
pg_hba.confand whether the service is up.
6. Packages vs Source Build
Choose packages unless you have a documented reason to compile.
| Approach | Use when | Avoid when |
|---|---|---|
| OS/PGDG packages | Production, patching, support contracts | You need unreleased patches |
| Docker image | Dev, CI, ephemeral environments | You need host-level tuning without containers |
| Source compile | Custom extensions, niche CPU flags | Standard OLTP with ops team bandwidth limits |
- Packages ship tested combinations of libraries and systemd units.
- Source builds shift patch responsibility to your team.
- Document the install method in your runbook either way.
Intermediate Examples
7. Docker for Local Dev
Run an isolated 18.x instance without touching the host install.
docker run -d \
--name pg18 \
-e POSTGRES_PASSWORD=devonly \
-p 5432:5432 \
-v pg18data:/var/lib/postgresql/data \
postgres:18.4- Named volume persists data across container restarts.
- Bind-mount host dirs only when you understand UID mapping on Linux.
- Never use default passwords outside localhost.
Related: pg_hba.conf & Authentication - tighten auth after bootstrap
8. Supported OS Baselines
Align host OS with vendor support windows.
| OS family | Baseline | Notes |
|---|---|---|
| Debian 12 / Ubuntu 22.04+ | LTS with PGDG | Primary choice for self-hosted |
| RHEL 9 / Rocky 9 | Enterprise standard | SELinux contexts matter for PGDATA |
| macOS 14+ | Dev only | Not a production Postgres host |
| Windows Server 2022 | Supported but rare | Prefer Linux for HA tooling ecosystem |
- Run a supported OS minor before upgrading PostgreSQL major.
- EOL OS + current Postgres is a compliance risk even if the binary installs.
- Cloud managed Postgres removes OS patching from your scope but not version policy.
Stack versions: This page was written for PostgreSQL 18.4 (stable 18, maintenance 17), pgvector 0.8+, PgBouncer 1.x, Patroni 3.x, and PostGIS 3.5+.