Skip to content
Related Articles
Open in App
Not now

Related Articles

Install PostgreSQL on Linux

Improve Article
Save Article
  • Last Updated : 24 Sep, 2021
Improve Article
Save Article

This is a step-by-step guide to install PostgreSQL on a Linux machine. By default, PostgreSQL is available in all Ubuntu versions as PostgreSql “Snapshot”. However other versions of the same can be downloaded through the PostgreSQL apt repository. 

We will be installing PostgreSQL version 11.3 on Ubuntu in this article. 

There are three crucial steps for the installation of PostgreSQL as follows: 

  1. Check for the current version of PostgreSQL on your Ubuntu 
  2. Install PostgreSQL 
  3. Verify the installation 

Check for the current version of PostgreSQL

You can check for the current version of PostgreSQL on your Ubuntu device by using the below command in the terminal: 

postgres -V 

Installing PostgreSQL on Ubuntu

After checking if you need an update of PostgreSQL, follow the below steps to install the latest PostgreSQL version: 

  • Step 1: Add the GPG key for connecting with the official PostgreSQL repository using the below command: 
wget --quiet -O - | sudo apt-key add -
  • Step 2: Add the official PostgreSQL repository in your source list and also add it’s certificate using the below command: 
sudo sh -c 'echo "deb `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
  • Step 3: Run the below command to install PostgreSQL: 
sudo apt update
sudo apt install postgresql postgresql-contrib 

Verifying the Installation of PostgreSQL

There are couple of ways to verify the installation of PostgreSQL like connecting to the database server using some client applications like pgAdmin or psql. 
The quickest way though is to use the psql shell. For that follow the below steps: 

  • Step 1: Open the terminal and run the below command to log into PostgreSQL server: 
sudo su postgres
  • Step 2: Now use the below command to enter the PostgreSQL shell: 
  • Step 3: Now run the below command to check for the PostgreSQL version: 
SELECT version();
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!