How to install a specific version of PostgreSQL in Ubuntu

If you run the command below in Ubuntu it will install the latest version of PostgreSQL in the Ubuntu repository.

# Installs the latest version of PostgreSQL
sudo apt install postgresql postgresql-client

As of writing it will install PostgreSQL version 14.

What if you do not want PostgreSQL 14?

If you want to install a specific version of PostgreSQL, you can run the commands below.

# Install PostgreSQL version 12
sudo apt install postgresql-12 postgresql-client-12

# Install PostgreSQL version 10
sudo apt install postgresql-10 postgresql-client-10

What if I can’t find the PostgreSQL version that I am looking for?

As of writing PostgreSQL 15 is still not visible in the current Ubuntu repository.

If you want to add PostgreSQL 15 or other versions to Ubuntu then you need to add the official PostgreSQL package repository running the commands below.

# Create the file repository configuration
$ sudo sh -c 'echo "deb $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# Import the repository signing key
$ wget --quiet -O - | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null

# Update list of available packages
$ sudo apt update

Listing installable versions of PostgreSQL in Ubuntu

To list all the known versions of PostgreSQL that you can install in Ubuntu, you can run the command below.

# Lists the known PostgreSQL
sudo apt-cache pkgnames | grep postgresql | sort

The list is a bit long, especially with the addition of the official PostgreSQL repository in the package list.

The commands above to install and check the versions of PostgreSQL were checked with Ubuntu 22.04 LTS. The commands will also work with other versions of Ubuntu.

In case it doesn’t work, kindly let me know in the comments below.

We hope this helps you install your desired version of PostgreSQL in Ubuntu.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.