Install PostgreSQL on Ubuntu

Database

By Jennifer Mathew

Updated on Jan 27, 2024

In this article, we'll explain how to install PostgreSQL on Ubuntu 22.04. We are installing the available latest version of PostgreSQL for now it is version 16. We'll keep updating the article as much as possible. 

It is a powerful, open source object-relational database system. PostgreSQL runs on all major operating systems and comes with many features aimed to help developers build applications, administrators to protect data integrity and build fault-tolerant environments.

Install PostgreSQL on Ubuntu

Let's get started with the installation process.

1 Update the server

Keep the server up to date

sudo apt-get update 

Install Repo

Next, we need to create repository file. It will help us to install latest version of PostgreSQL. Use following command to install it.

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

Import signing key

Next, import the repository signing key, it help us to verify the installation.

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

Update the package lists

Let's update the package lists because we have created new repository file and it need to update to reflect it.

sudo apt-get update

Install PostgreSQL

Finally, execute following command to install PostgreSQL. Here you can mention specific version too. Like postgresql-14

sudo apt-get -y install postgresql

That's it. We have successfully install PostgreSQL on Ubuntu 22.04.