How to Install PostgreSQL on Ubuntu 22.04

PostgreSQL is a widely-used, free, and open-source relational database management system (RDBMS) known for being highly secure, reliable, flexible, and robust. Additionally, it provides support and compatibility across various platforms, such as macOS, Linux, Windows, and other Unix-like operating systems. This cross-platform compatibility enables Ubuntu users to easily install and utilize PostgreSQL on their operating system based on their specific requirements.

This article illustrates how to install PostgreSQL on Ubuntu 22.04 using a step-by-step guide.

How to Install PostgreSQL on Ubuntu 22.04?

Installing Postgres on Ubuntu 22.04 is not too complicated if you execute the proper instructions. For that particular purpose, simply follow the steps outlined below:

Step 1: Update the System Packages

It is considered a good practice to update the system packages on Ubuntu before installing any new software or packages. To do this, simply execute the following command:

sudo apt update

Step 2: Install Postgres

Once you have successfully updated the system packages, execute the below-given command to install PostgreSQL on your Ubuntu machine:

sudo apt-get install postgresql

Then, press “y” from the keyboard to continue the installation process:p

In the above snippet, we installed the latest version of PostgreSQL on Ubuntu 22.04. However, if you want to install a particular version of PostgreSQL, make sure to specify the version number as well:

sudo apt-get install postgresql-version

Replace “version” with the version number that you want to install on your system.

Step 3: Verify Postgres Installation

Once you are done with the installation process, verify the Postgres installation with the below-exhibited command:

pg_config --version

The output confirms that Postgres version “14.8” has been successfully installed on Ubuntu “22.04”:

Step 4: Start Postgres Service

Now, start the Postgres service by running the below-provided command:

sudo systemctl start postgresql.service

Step 5: Switch User

In order to access or use the Postgres database on Ubuntu 22.04, first, you need to switch to the “postgres” user account. For this purpose, execute the following “sudo” command:

$ sudo -i -u postgres

Step 6: Connect to Postgres

Next, execute the “psql” command to establish a connection with the Postgres database:


Once you enter the psql terminal, you can perform any task related to PostgreSQL, such as creating a database, creating a table, deleting a table, and so on.


To install PostgreSQL on Ubuntu 22.04, begin by updating the system packages with the “sudo apt update” command. After that, use the “sudo apt-get install postgresql” command to install Postgres on your system.

To start the Postgres service, use the “sudo systemctl start postgresql.service” command. Then, connect to Postgres by running “sudo -i -u postgres” command. Finally, access the command line utility of PostgreSQL by running the “psql” command. This write-up has demonstrated all the steps required for the installation of PostgreSQL on Ubuntu 22.04.

Print Friendly, PDF & Email