DEV Community

Cover image for POSTGRESQL INSTALLATION MADE EASY ON LINUX SERVERS
Njeri Kimaru
Njeri Kimaru

Posted on

POSTGRESQL INSTALLATION MADE EASY ON LINUX SERVERS

STEP BY STEP GUIDE ON INSTALLATION OF PostgreSQL ON A LINUX SERVER.

INTRODUCTION

PostgreSQL has overtaken the database system and learning how to install it is an essential skill as it is used in various web applications and data driven applications. In this article we will learn how to install PostgreSQL on a Linux server hosted by Microsoft Azure. This tutorial will include creating a virtual Linux computer, connecting it using SSH with Gitbash and installing PostgreSQL.

What you'll need;

A Microsoft Azure account.
A Gitbash app in your computer.
A Gitbash account.

STEP 1: Create a virtual Linux computer on Microsoft Azure.

  1. Go to https://portal.azure.com
  2. In the search bar, type Virtual machines
  3. Click + Add > Virtual machine
  4. Fill in the form:

    • Name: student1
    • Region: Choose the closest location
    • Image: Ubuntu 20.04 LTS
    • Size: Standard B1s (or any small size)
    • Authentication Type: SSH public key
    • Username: e.g., student
  5. Click Review + Create

  6. Click Create

    Important: Save your private SSH key, you’ll need it to connect to the VM.

STEP 2: Login to the virtual computer using SSH with Gitbash.

Go to the virtual computer and copy the IP address.
Open Git Bash on your computer and type the following code.
ssh ssh -i /path/to/your/student1 student@IP address
If prompted type yes to continue.

STEP 3: Install PostgreSQL on Linux server.

Once you are logged into the server enter the following commands.

sudo apt update
sudo apt install postgresql postgresql-contrib -y

STEP 4: Check PostgreSQL status.

Run the following command;
sudo systemctl status postgresql

STEP 5: Start and enable PostgreSQL

Run the following commands;

sudo systemctl start postgresql
sudo systemctl enable postgresql

STEP 6: Swith to PostgreSQL user.

Run the command;
sudo -i -u postgres
Then enter PostgreSQL shell;
psql

STEP 7: Create a database.

Inside the psql shell you can create a database;
CREATE DATABASE sampled;
\l -- to list databases
\!q -- to exit
To go back to regular user; exit

CONCLUSION.

Your PostgreSQL is now succesfully installed onto your virtual Linux server.
This setup is ideal for beginners who are learning how to install PostgrSQL on their virtual Linux server. From here you can connect PostgreSQL to tool like Dbeaver.

Top comments (0)