How to Install Postgres on Ubuntu 20.04

ℹ️Update, August 2026: Ubuntu 20.04 LTS reached the end of its standard support in 2025. The steps below work the same on current releases, just use a supported version like 24.04 (apt package names below are unchanged).
🐧Part of the WSL Complete Guide, every Windows Subsystem for Linux post on this site, organised by task.

This post is a short note on how to install Postgres on Ubuntu 20.04.

I’m doing this in WSL, however this shouldn’t make any difference if you’re on the same Ubuntu version.


Update Local Packages

First, lets update our local packages by running the following apt command –

# update local packages
sudo apt update
Running sudo apt update in an Ubuntu terminal

Install PostgreSQL

This Postgres installation is very quick and simple.

The following command is also including the ‘-contrib‘ package which gives us extra functionalities.

# install postgres on ubuntu
sudo apt install postgresql postgresql-contrib
Installing PostgreSQL on Ubuntu with sudo apt install postgresql postgresql-contrib

Log In to psql

Once the installation completes, we can enter psql using the postgres user created automatically during the install.

# login to psql with the out of box postgres user
sudo -u postgres psql

\q (to quit back to terminal)
Logging in to psql for the first time as the default postgres user

Restart the Service

There may be a need to restart the services post install which can be done by running the following.

# restart postgres service ubuntu
sudo service postgresql restart
Restarting the PostgreSQL service on Ubuntu with sudo service postgresql restart

Related

If SQL Server is part of your day job, my current work lives over at sqldba.blog: production DBA scripts, an error library and the SSMS guide.


Comments

Leave a Reply

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

Looking for SQL Server?

This site started as a SQL Server blog in 2017 and the archive is still here. The new SQL Server writing, and all the scripts, moved to a site of their own.

sqldba.blogScripts, error library, wait types, SSMS
Browse by topic