Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Ubuntu 20.04 - Install PostgreSQL

Similar Posts

Native Package - PostgreSQL 12

sudo apt update \
  && sudo apt install postgresql-12

PostgreSQL Repository

If you want to install the very latest version of PostgreSQL (current PostgreSQL 13), then you will need to add their repository which can be done with the script 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 apt-key add -

# Update the package lists:
sudo apt-get update

... then you can install whichever version you want, including version 13.

sudo apt-get -y install postgresql-13

Check Version

If you want to check what version of PostgreSQL you are now running, use the following command:

sudo -u postgres psql postgres -c 'SELECT version()' | grep PostgreSQL

Configure It

After having installed PostgreSQL, you probably want to spend a bit of time configuring it (passwords etc).


Last updated: 26th October 2020
First published: 23rd October 2020