How to install PostgreSQL 13 in Ubuntu?

If the version included in your version of Ubuntu is not the one you want, you can use the PostgreSQL Apt Repository. This repository will integrate with your normal systems and patch management, and provide automatic updates for all supported versions of PostgreSQL throughout the support lifetime of PostgreSQL.

The PostgreSQL Apt Repository supports the current LTS versions of 18.04 & 16.04

on the following architectures: amd64 i386 ppc64el

While not fully supported, the packages often work on other non-LTS versions as well, by using the closest LTS version available. To use the apt repository, follow these steps:

Create the file /etc/apt/sources.list.d/pgdg.list and add a line for the repository

deb http://apt.postgresql.org/pub/repos/apt/ YOUR_UBUNTU_DISTRIB_CODENAME_HERE-pgdg main

Import the repository signing key, and update the package lists

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update

From https://www.postgresql.org/download/linux/ubuntu/


sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

sudo apt-get update

# Specify/replace the version number you want to install

sudo apt-get -y install postgresql-13

The latest version of postgresql-client and postgresql-11 in the Ubuntu 19.04 and 19.10 default repositories is version 11. To install these packages run:

sudo apt install postgresql-client postgresql-11

The latest version of postgresql-client and postgresql-XX in the Ubuntu 20.04 default repositories is version 12.

sudo apt install postgresql-client-12 postgresql-12