Installation Basics
8 examples for installing PostgreSQL 18 on common platforms - 6 basic and 2 intermediate.
Search across all documentation pages
8 examples for installing PostgreSQL 18 on common platforms - 6 basic and 2 intermediate.
# Verify you have sudo or root for package installs
uname -apostgres account, never as root.Confirm what is already on the host before changing anything.
psql --version
postgres --versionpsql is the client; postgres is the server binary.pg_dump restores.SELECT version(); instead.Related: initdb & Data Directory - first cluster setup
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-18postgresql-18 creates a cluster via initdb automatically on Debian-family systems.postgresql metapackage alone.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-18postgresql module to avoid version conflicts.postgresql-18-setup initdb creates PGDATA under /var/lib/pgsql/18/data.Related: Systemd & Service Management - start/stop/reload
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"' >> ~/.zshrcpostgres system user - your macOS user owns the data dir.PATH for psql and initdb.Connect locally and read the catalog version.
SELECT version();
SHOW server_version;
SHOW data_directory;server_version is the numeric GUC; version() includes build flags.data_directory confirms which PGDATA this instance uses.pg_hba.conf and whether the service is up.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 |
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.4Related: pg_hba.conf & Authentication - tighten auth after bootstrap
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 |
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+.
Reviewed by Chris St. John·Last updated Jul 18, 2026