PostgreSQL 18 Installation & Setup Guide for Debian and Ubuntu

A production-ready, step-by-step guide to installing PostgreSQL 18 on Debian and Ubuntu using the official PostgreSQL APT repository. Covers secure installation, user and database setup, authentication configuration, and best practices for modern web applications.

Techno Drishti

Technology & Innovation Team

A collective of developers, designers, and engineers building scalable digital solutions and sharing practical insights from the field.

3 min read 450 words
PostgreSQL 18 Installation & Setup Guide for Debian and Ubuntu

PostgreSQL 18 Installation & Setup Guide

Target OS: Ubuntu / Debian PostgreSQL Version: 18 (latest stable) Audience: Developers (Next.js, Django, Laravel, NestJS, etc.)


Overview

This document describes how to install PostgreSQL 18 on Debian or Ubuntu using the official PostgreSQL APT repository, followed by basic configuration suitable for application development and production use.

Ubuntu/Debian default repositories may ship older PostgreSQL versions. Using the official PostgreSQL repository ensures access to the latest supported release and timely security updates.


Step 0: Add the Official PostgreSQL APT Repository

Required to install PostgreSQL 18

sudo apt install curl ca-certificates gnupg -y

curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc \
  | sudo gpg --dearmor -o /usr/share/keyrings/postgresql.gpg

echo "deb [signed-by=/usr/share/keyrings/postgresql.gpg] \
http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" \
  | sudo tee /etc/apt/sources.list.d/pgdg.list

sudo apt update

Step 1: Update System Packages

sudo apt update
sudo apt upgrade -y

Step 2: Install PostgreSQL 18

Installs:

  • PostgreSQL server
  • PostgreSQL client
  • Common extensions
sudo apt install postgresql-18 postgresql-client-18 postgresql-contrib -y

Step 3: Verify PostgreSQL Service

Check service status:

sudo systemctl status postgresql

If not running:

sudo systemctl start postgresql
sudo systemctl enable postgresql

Step 4: Switch to the postgres System User

PostgreSQL creates a system user named postgres.

sudo -i -u postgres

Step 5: Access PostgreSQL Shell (psql)

psql

Expected prompt:

postgres=#

Exit:

\q

Step 6: Set Password for postgres User

ALTER USER postgres PASSWORD 'strongpassword';

Step 7: Create a Database

CREATE DATABASE mydb;

Do not use the postgres user in applications.

CREATE USER myuser WITH PASSWORD 'mypassword';

Grant privileges:

GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;

Step 9: Enable Password Authentication

Edit authentication configuration:

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

Change:

local   all   all   peer

To:

local   all   all   md5

Restart PostgreSQL:

sudo systemctl restart postgresql

Step 10: Test Login

psql -U myuser -d mydb

Successful login confirms correct setup.


Version Verification

psql --version

Expected output:

psql (PostgreSQL) 18.x

Connection String Example

postgresql://myuser:mypassword@localhost:5432/mydb

Notes & Best Practices

  • PostgreSQL 18 is the latest stable and actively supported release
  • PostgreSQL 17, 16, 15, 14 are still supported
  • PostgreSQL 13 and below are end-of-life and should not be used
  • Always use a dedicated database user for applications
  • For production, consider:
    • SSL connections
    • Automated backups
    • Role-based permissions

About the Author

Techno Drishti

Technology & Innovation Team

A collective of developers, designers, and engineers building scalable digital solutions and sharing practical insights from the field.

Related Articles

Continue exploring topics you might find interesting

database

MariaDB Installation

MariaDB Installation and Usage on Linux (Debian/Ubuntu)

Read Article
lms

Koha LMS Installation Guide on Linux (Debian/Ubuntu)

This document provides a **clear, step-by-step, production-oriented guide** to install **Koha Integrated Library Management System (LMS)** on a Linux server, specifically **Debian or Ubuntu**. Koha officially recommends Debian-based systems and this guide follows best practices used in real-world library deployments.

Read Article
devops

Gitea Setup on Debian/Ubuntu (LAN Access, PostgreSQL, Apache)

A step-by-step guide to setting up Gitea on Debian/Ubuntu with LAN access, PostgreSQL, and Apache.

Read Article

Enjoyed this article?

Get notified when I publish new content. No spam, just quality articles delivered to your inbox.