
Introduction
This tutorial will give you a step by step guide on how to install PostgreSQL 12 on Ubuntu 16.04/18.04/20.04. All software used in this tutorial are open-source and therefore are all free. I am currently using amazon’s aws free tier to host and conduct this tutorial. before we start, I must also note that the version of Ubuntu that i am using in this tutorial is version 18.04, also you must have root access, whether it be by su – root or by using sudo as a next user. So let jump right into “how to install PostgreSQL 12 on Ubuntu 16.04/18.04/20.04”.
System Update
To begin, we will first need to update our system packages by executing the codes below individually:
sudo apt update sudo apt -y install vim bash-completion wget sudo apt -y upgrade
Add repository
We will need to add the PostgreSQL 12 repository by running individually:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" |sudo tee /etc/apt/sources.list.d/pgdg.list
Install PostgreSQL 12
Now its time to install PostgreSQL 12 on our Ubuntu OS to do so, execute the commands that are shown below individually. You can follow the gif below to see what exactly to do.
sudo apt update sudo apt -y install postgresql-12 postgresql-client-12
Installation Success
Now that installation has completed successfully, you should see the message below instructing you on how to start the database and some general information on the cluster:
Switch to Postgres
Switch to the Postgres user by running the command :
sudo su postgres
connecting to the interactive shell
To connect to the postgresql interactive shell and the database please see our article on 20 PostgreSQL basic administrative commands you need to know. This Article will show you how to interact with the database.
External Access
By default PostgreSQL only allows local access after an installation. To allow access to external i.p. addresses, we will need to make changes to the pg_hba.conf file. Here is a link to a previous article we wrote that covers how to manipulate the pg_hba.conf file Understanding the pg_hba conf file in PostgreSQL.