Introduction

In this tutorial I will walk you step by step on how to install Postgres using the terminal for either Linux or MacOs operating system.

I assume that you know some basic command using the terminal or command line with superuser permission.

apt-get

I use apt-get package manager to install postgresql. Before that lets update the package manager

$ sudo apt-get update

Next let’s see whether Postgresql is available in the repository system.

$ apt-cache policy postgresql

Once pressed return

postgresql:
    Installed: (none)
    Candidate: 11+200+deb10u5
    Version table:
    *** 11+200+deb10u5 500
            500 http://ftp.us.debian.org/debian buster/main amd64 Packages
            100 /var/lib/dpkg/status
            11+200+deb10u3 500

As you can see it’s not yet install but it is available with a current version in the repo.

Now it is time to install Postgresql

$ sudo apt-get install postgresql postgresql-contrib

After finished with postgresql installation again type into terminal

$ apt-cache policy postgresql

It will prompt in terminal

postgresql:
    Installed: 11+200+deb10u5
    Candidate: 11+200+deb10u5
    Version table:
    *** 11+200+deb10u5 500
            500 http://ftp.us.debian.org/debian buster/main amd64 Packages
            100 /var/lib/dpkg/status
            11+200+deb10u3 500

Its print that postgresql has been installed into the system.

Run postgesql

$ sudo su - postgresql

and proceed

psql

You can see Postgres version and start run in the terminal