How to Manually Install PostgreSQL 18 on Ubuntu 24.04
This guide explains how to manually install PostgreSQL 18 on an Ubuntu 24.04 server.
The instructions in this article are based directly on the supplied PostgreSQL Ansible playbook. Instead of using Ansible to perform the installation automatically, the commands below allow you to perform the same installation steps manually from the Ubuntu terminal.
Operating System: Ubuntu 24.04 LTS
Application: PostgreSQL 18
1. What You Will Install
After completing this guide, PostgreSQL 18 will be installed on your Ubuntu 24.04 server.
The installation will include:
- PostgreSQL 18
- PostgreSQL official APT repository
- PostgreSQL repository signing key
- PostgreSQL service
The PostgreSQL service will also be enabled so that it starts automatically when the server boots.
2. Requirements
Before starting, make sure you have:
- Ubuntu 24.04 LTS installed
- Access to the Ubuntu terminal
- A user account with
sudoprivileges - An active internet connection
You can check your Ubuntu version with:
lsb_release -a
Make sure the system reports Ubuntu 24.04.
3. Update Ubuntu
First, update the Ubuntu package information.
sudo apt update
You can also upgrade installed packages:
sudo apt upgrade -y
Wait for the command to finish before continuing.
4. Install the Required Packages
The PostgreSQL Ansible playbook installs the following required packages:
curlca-certificatespostgresql-common
Install them manually using:
sudo apt install -y curl ca-certificates postgresql-common
These packages are required to configure the PostgreSQL repository and securely download PostgreSQL packages.
5. Create the PostgreSQL Keyring Directory
The Ansible playbook creates a directory for the PostgreSQL repository signing key.
Create the directory manually:
sudo mkdir -p /usr/share/postgresql-common/pgdg
Set the directory permissions:
sudo chmod 755 /usr/share/postgresql-common/pgdg
You can verify that the directory exists:
ls -ld /usr/share/postgresql-common/pgdg
6. Download the PostgreSQL Repository Signing Key
PostgreSQL provides an official repository signing key. The Ansible playbook downloads the key from the PostgreSQL website.
Run:
sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc \
https://www.postgresql.org/media/keys/ACCC4CF8.asc
The key will be stored at:
/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc
Set the permissions to match the Ansible playbook:
sudo chmod 644 /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc
Verify the key file:
ls -l /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc
7. Add the Official PostgreSQL Repository
The Ansible playbook adds the official PostgreSQL APT repository. This repository is used to install PostgreSQL 18.
Create the repository configuration file:
sudo nano /etc/apt/sources.list.d/pgdg.sources
Copy and paste the following into the file:
Types: deb deb-src
URIs: https://apt.postgresql.org/pub/repos/apt
Suites: noble-pgdg
Architectures: amd64
Components: main
Signed-By: /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc
Save the file:
- Press CTRL + O
- Press ENTER
- Press CTRL + X
8. Update APT
Ubuntu now needs to read the PostgreSQL repository that was just added.
Run:
sudo apt update
If the command completes successfully without repository errors, continue to the next step.
9. Install PostgreSQL 18
The Ansible playbook installs PostgreSQL version 18 using the package:
postgresql-18
Install PostgreSQL 18 manually:
sudo apt install -y postgresql-18
Allow the installation to finish.
10. Enable the PostgreSQL Service
The Ansible playbook enables the PostgreSQL system service. This means PostgreSQL will automatically start when Ubuntu starts.
Run:
sudo systemctl enable postgresql
11. Start PostgreSQL
Start the PostgreSQL service:
sudo systemctl start postgresql
12. Check the PostgreSQL Service
Check whether PostgreSQL is running:
sudo systemctl status postgresql
Look for:
Active: active (running)
If the service is running, PostgreSQL has started successfully.
Press Q to exit the status screen.
13. Check the PostgreSQL Version
The Ansible playbook checks the installed PostgreSQL version using the psql command.
Run:
psql --version
You should see output similar to:
psql (PostgreSQL) 18.x
The exact minor version number may be different depending on the PostgreSQL package currently available in the repository.
14. Check Which PostgreSQL Service Is Running
You can check the PostgreSQL service with:
sudo systemctl is-active postgresql
The expected result is:
active
Check whether it is enabled at startup:
sudo systemctl is-enabled postgresql
The expected result is:
enabled
15. Check PostgreSQL Clusters
Ubuntu's PostgreSQL packages use PostgreSQL clusters to manage database server instances.
You can display the available clusters with:
pg_lsclusters
This command can help confirm that a PostgreSQL cluster has been created and is running.
16. Check PostgreSQL Listening Ports
PostgreSQL normally listens for database connections on TCP port 5432.
Check whether PostgreSQL is listening:
sudo ss -ltnp | grep 5432
If PostgreSQL is listening, you should see a result containing port 5432.
17. Test PostgreSQL
PostgreSQL provides a command-line client called psql.
You can test the local PostgreSQL server by connecting as the PostgreSQL system administrator:
sudo -u postgres psql
If the connection is successful, you will see a PostgreSQL prompt similar to:
postgres=#
Run the following command inside PostgreSQL to check the server version:
SELECT version();
To exit PostgreSQL, type:
\q
18. Verify the Installation
Run the following commands one at a time:
psql --version
sudo systemctl status postgresql
sudo systemctl is-active postgresql
sudo systemctl is-enabled postgresql
pg_lsclusters
sudo ss -ltnp | grep 5432
If PostgreSQL reports version 18, the service is active, the service is enabled, and the PostgreSQL cluster is running, the installation has been completed successfully.
19. Useful PostgreSQL Commands
Check PostgreSQL version
psql --version
Check PostgreSQL service
sudo systemctl status postgresql
Start PostgreSQL
sudo systemctl start postgresql
Stop PostgreSQL
sudo systemctl stop postgresql
Restart PostgreSQL
sudo systemctl restart postgresql
Enable PostgreSQL at startup
sudo systemctl enable postgresql
Check whether PostgreSQL is running
sudo systemctl is-active postgresql
Check whether PostgreSQL starts automatically
sudo systemctl is-enabled postgresql
List PostgreSQL clusters
pg_lsclusters
Connect to PostgreSQL
sudo -u postgres psql
Check the database server version from inside PostgreSQL
SELECT version();
Exit PostgreSQL
\q
Check PostgreSQL port
sudo ss -ltnp | grep 5432
20. Installation Summary
The manual installation follows the same main sequence as the supplied PostgreSQL Ansible playbook:
- Install the required packages.
- Create the PostgreSQL keyring directory.
- Download the PostgreSQL repository signing key.
- Add the official PostgreSQL repository.
- Update the APT package cache.
- Install PostgreSQL 18.
- Enable the PostgreSQL service.
- Start PostgreSQL.
- Check the PostgreSQL version.
- Verify that PostgreSQL is running.
21. Final PostgreSQL Information
| Item | Value |
|---|---|
| Application | PostgreSQL |
| Version | 18 |
| Operating System | Ubuntu 24.04 LTS |
| Service | postgresql |
| Default PostgreSQL Port | 5432 |
| PostgreSQL Repository | apt.postgresql.org |
| Repository Suite | noble-pgdg |
PostgreSQL 18 has been installed on Ubuntu 24.04. The PostgreSQL service has been enabled and started, and the installation can be verified using
psql --version and sudo systemctl status postgresql.Note: This article converts the installation tasks contained in the supplied PostgreSQL Ansible playbook into manual Ubuntu terminal commands.

