Ubuntu’s default repositories contain PostgreSQL packages, so you can install them using the "apt install" command.
Step 1: Update your local package repository.
$ sudo apt-get update
Step 2: Install the postgres package. You can also install postgresql-contrib package that adds some additional utilities and functionality.
$ sudo apt install postgresql postgresql-contrib
The PostgreSQL is now installed. To access it from the command line, run the following command:
$ sudo -u postgres psql postgres
This will log you into the PostgreSQL prompt. You can run your SQLs there.
psql (12.6 (Ubuntu 12.6-0ubuntu0.20.04.1))
Type "help" for help.
postgres=#