How to install PostgreSQL 14 on Ubuntu 20.04 from the source

In this article, we are going to learn how to install and get PostgreSQL 14 up and running on an Ubuntu 20.04 server. PostgreSQL is a powerful, open-source object-relational database system that uses and extends the SQL language combined with many features that safely store and scale the most complicated data workloads.

Install PostgreSQL 14 on Ubuntu 20.04

Ubuntu comes with a default PosgreSQL in its APT repositories. To check the default in the repositories, we can use the following command.

$ sudo apt-cache search postgresql | grep postgresql

postgresql - object-relational SQL database (supported version)
postgresql-12 - object-relational SQL database, version 12 server
postgresql-client - front-end programs for PostgreSQL (supported version)
postgresql-client-12 - front-end programs for PostgreSQL 12
postgresql-client-common - manager for multiple PostgreSQL client versions
postgresql-common - PostgreSQL database-cluster manager
postgresql-contrib - additional facilities for PostgreSQL (supported version)
postgresql-doc - documentation for the PostgreSQL database management system
postgresql-doc-12 - documentation for the PostgreSQL database management system

As you can see, Ubuntu 20.04 comes with a default PostgreSQL 12.

Update system repositories

Let’s first update our repositories in order to make them up to date.

$ sudo apt update && apt upgrade -y

Install PostgreSQL dependencies

We need to have the following dependencies installed first before we can proceed to install from the source.

$ sudo apt install build-essential zlib1g-dev libreadline-dev -y

Download PostgreSQL 14 from source

Head over to postgresql ftp server to download the latest version

$ wget

Next, we need to extarct this downloaded content.

$ tar xvfz postgresql-14.2.tar.gz

Then next we are going to cd into it then do configuration and do make and lastly sudo make install.

cd postgresql-14.2
make install

Add a Postgres user

To allow us run administrative jobs we need to add a postgres user and also because we didnt install from the APT repository, its ncessary to install Postgresql-contrib first.

$ sudo apt install postgresql-contrib

Add a postgres user password with this command.

$ sudo passwd postgres 

and to switch to the postgres user use this command

$ su postgres
$ psql
psql (14.2 (Ubuntu 14.2-1ubuntu1))
Type "help" for help.

postgres=# \l
                              List of databases
   Name    |  Owner   | Encoding | Collate |  Ctype  |   Access privileges   
 postgres  | postgres | UTF8     | C.UTF-8 | C.UTF-8 | 
 template0 | postgres | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres          +
           |          |          |         |         | postgres=CTc/postgres
 template1 | postgres | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres          +
           |          |          |         |         | postgres=CTc/postgres
(3 rows)

To check the version of the PostgreSQL installed use this command.

postgres=# SELECT version();
 PostgreSQL 14.2 (Ubuntu 14.2-1ubuntu1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, 64-bit
(1 row)



Congratulations you have installed PostgreSQL 14 from the source.

About Kipkoech Sang

I am a technology enthusiast who loves to share gained knowledge through offering daily tips as a way of empowering others. I am fan of Linux and all other things open source.
View all posts by Kipkoech Sang →

Leave a Reply

Your email address will not be published.