Updated: 28 September 2026 · Applies to: Ubuntu 24.04 (PostgreSQL 16 and 18)
Ubuntu 18.04 and PostgreSQL 10 are end of life. The current PostgreSQL version is 18; Ubuntu 24.04 ships version 16, which is supported until 2028.
Client only
To connect to a PostgreSQL server elsewhere, install just the client: apt install postgresql-client.
Option 1: the distribution's version
apt install postgresql # Ubuntu 24.04: PostgreSQL 16, Debian 12: 15 dnf install postgresql-server # AlmaLinux / Rocky 9 (choose a stream with: dnf module list postgresql) postgresql-setup --initdb && systemctl enable --now postgresql # AlmaLinux / Rocky only
Option 2: the latest PostgreSQL (18) from the PostgreSQL project
# Ubuntu / Debian apt install postgresql-common /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh apt install postgresql-18 # AlmaLinux / Rocky 9 dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm dnf -qy module disable postgresql dnf install postgresql18-server /usr/pgsql-18/bin/postgresql-18-setup initdb systemctl enable --now postgresql-18
First steps
sudo -u postgres psql # log in as the admin role CREATE ROLE appuser WITH LOGIN PASSWORD 'Strong-Password'; CREATE DATABASE appdb OWNER appuser; \l -- list databases \du -- list roles \q -- quit
Connect as the new user: psql -h 127.0.0.1 -U appuser appdb.
Allow connections from another server (optional)
- In
postgresql.confsetlisten_addresses = '*'(or the server's private IP). - In
pg_hba.confaddhost appdb appuser 203.0.113.10/32 scram-sha-256. - Restart PostgreSQL and open port 5432 only for that IP in the firewall.
The files are in /etc/postgresql/<version>/main/ (Ubuntu/Debian), /var/lib/pgsql/data/ (AlmaLinux/Rocky packages) or /var/lib/pgsql/18/data/ (PostgreSQL project packages).