PostgreSQL 16 is a powerful, standards-compliant open-source relational database. This guide installs PostgreSQL 16 on Ubuntu 24.04 LTS using the official PGDG repository for the latest release.

Tested and valid on:

  • Ubuntu 24.04 LTS

Prerequisites

  • Ubuntu 24.04 LTS server
  • A user with sudo privileges

Step 1 – Add the PostgreSQL APT Repository

Import the signing key and add the PGDG repo:

sudo apt install -y curl ca-certificates
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/keyrings/postgresql.gpg
echo "deb [signed-by=/etc/apt/keyrings/postgresql.gpg] https://apt.postgresql.org/pub/repos/apt noble-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list

Step 2 – Install PostgreSQL 16

Update and install:

sudo apt update
sudo apt install postgresql-16 -y

Step 3 – Verify the Service

Check that PostgreSQL is running:

sudo systemctl status postgresql

Step 4 – Connect to PostgreSQL

PostgreSQL creates a default postgres system user. Switch to it and open the shell:

sudo -i -u postgres
psql

Step 5 – Create a Database and User

Inside psql:

CREATE DATABASE mydb;
CREATE USER myuser WITH ENCRYPTED PASSWORD 'StrongPassword123!';
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
q

Step 6 – Allow Password Authentication

Edit pg_hba.conf to allow md5/scram authentication for local connections:

sudo nano /etc/postgresql/16/main/pg_hba.conf

Change peer to scram-sha-256 for local connections, then restart:

sudo systemctl restart postgresql

Step 7 – Check the Version

Verify the installed version:

psql --version

Conclusion

PostgreSQL 16 is now running on Ubuntu 24.04 LTS. It offers advanced features like JSON support, full-text search, and window functions that make it ideal for complex applications.