Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Install PostgreSQL on Ubuntu
#1


    How to Install PostgreSQL on Ubuntu

   

Before proceeding, ensure your virtual private server (VPS) runs Ubuntu 20.04 or later.


   

Option 1 – Installation From APT Repository



   

The popular method to install PostgreSQL on Ubuntu is from the official repository via the APT package manager. Here are the steps to do so:


   
           
  1. Run these commands to import the key from PostgreSQL’s official repository to the APT package manager:
               
    sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
               
    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg -
           

  2.        
  3. Refresh APT to synchronize all repositories using this command:
               
    sudo apt update
           

  4.        
  5. Install the latest version of PostgreSQL with APT and sudo privileges:
               
    sudo apt-get -y install postgresql
           

  6.        
  7. To confirm the installation, run this command:
               
    sudo -u postgres psql
           

  8.        
  9. Enter the PostgreSQL version query statement:
               
    SELECT version();
           
  10.    

   

Option 2 – Installation Using Local Ubuntu Repository



   

The alternative PostgreSQL installation method uses the local Ubuntu repository. Here are the steps:


   
           
  1. Run this command to refresh the Ubuntu repository:
               
    sudo apt-get update
           

  2.        
  3. Verify the available PostgreSQL apt repository using this command:
               
    sudo apt show postgresql
           

  4.        
  5. Run this command to install the latest available version. In our case, it is version 12.15:
               
    sudo apt install postgresql postgresql-contrib
           

  6.        
  7. To verify whether the PostgreSQL installation is successful, run the following:
               
    sudo -u postgres psql
           

  8.        
  9. Then, run this command to check the current PostgreSQL version:
               
    SELECT version();
           
  10.    

   

The command line should show that the PostgreSQL server version 12.15 is successfully installed, similar to this:

   

   

   

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)