Why I Wrote This

While setting up my development environment on Ubuntu 24.04 (Noble Numbat), I noticed the default PostgreSQL version in Ubuntu’s repository was outdated.
So I decided to document the clean, official way to install the latest PostgreSQL (v18) — straight from the PostgreSQL Apt repository.

If you’ve ever run into issues like:

  • “No cluster suitable as a default target”

  • or old versions like PostgreSQL 14 or 15 being installed instead of the latest then this guide will help you start fresh.

Step-by-Step Guide to Installing PostgreSQL 18

Step 1 — Update and Upgrade Your System

sudo apt update && sudo apt upgrade -y

Step 2 — Check Your Ubuntu Codename:

PostgreSQL’s official repo depends on your Ubuntu version codename.
Run the following to check yours:

. /etc/os-release
echo $VERSION_CODENAME

For Ubuntu 24.04, the output should be:

noble

Step 3 — Install the Necessary Software Packages

In this step, you will need to install all the required

We’ll install curl, ca-certificates, and postgresql-common:

sudo apt install -y curl ca-certificates postgresql-common

Step 4 — Add the PostgreSQL Apt Repository

Run the following command to automatically add the official PostgreSQL repository:

sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh

Step 5 — Update Package Lists & Install PostgreSQL 18

sudo apt update
sudo apt install -y postgresql-18

When prompted during installation:

  • Type Y to confirm.

  • If you see a purple configuration screen like this 👇 choose
    “install the package maintainer’s version”
    (This ensures a clean, default setup for PostgreSQL 18.)

Step 7 — Verify Installation

Check the installed version you should see:

psql --version
psql (PostgreSQL) 18.x

That’s it! You’ve successfully installed and verified PostgreSQL 18 on Ubuntu 24.04 (Noble).
Your system is now running the latest, officially supported PostgreSQL version, ready for use in production or local development.If you encounter any issues, check the PostgreSQL service logs with:

sudo journalctl -u postgresql

Otherwise — you’re all set to start building with PostgreSQL 18.

Keep Reading