Skip to Content

How to Install PostgreSQL on Ubuntu Linux 20.04

PostgreSQL is a powerful, open source object-relational database system with over 30 years of active development. This tutorial will show you how to install the latest version of PostgreSQL on Ubuntu Linux 20.04.

Install PostgreSQL on Ubuntu Linux 20.04

PostgreSQL is available in Ubuntu’s repositories and can be installed by running the following commands.

sudo apt update
sudo apt install -y postgresql

However, after running psql -V psql you will notice the installed version is not the latest. As of writing, the Ubuntu 20.04 repository contains PostgreSQL 12.9 when the latest version is 14.1.

How to install the latest version of PostgreSQL on Ubuntu

We can install the latest version of PostgreSQL from the official PostgreSQL repository by following the steps below.

Step 1: Create the file repository configuration

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

Step 2: Import the repository signing key

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

Step 3: Update package lists and install PostgreSQL

sudo apt-get update
sudo apt-get -y install postgresql

Step 4: Check installed version

Run the following command to see if PostgreSQL was installed and to see the version.

psql -V psql

Output

psql (PostgreSQL) 14.1 (Ubuntu 14.1-2.pgdg20.04+1)

Summary

In this tutorial we learned how to install the latest version of PostgreSQL on Ubuntu Linux 20.04.