How to Install PostgreSQL 9.6 on Ubuntu 18.04 LTS within 3 minutes

2020-01-07

Watch

At Will & Skill we are avid users of Postgres due to its simplicity and deep integration with the Django ORM. If You have not used Postgres before, You should definitely give it a try.

1. Add Postgres to as a APT repository

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 -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -

2. Install Postgres

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install postgresql postgresql-contrib libpq-dev 

3. Connect to Postgres

sudo su postgres
psql

The output should look like

postgres@bananabase-com:~$ psql
psql (10.4 (Ubuntu 10.4-2.pgdg18.04+1))
Type "help" for help.

postgres=# \l
                              List of databases
   Name    |  Owner   | Encoding | Collate |  Ctype  |   Access privileges
-----------+----------+----------+---------+---------+-----------------------
 postgres  | postgres | UTF8     | C.UTF-8 | C.UTF-8 |
 template0 | postgres | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres          +
           |          |          |         |         | postgres=CTc/postgres
 template1 | postgres | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres          +
           |          |          |         |         | postgres=CTc/postgres
(3 rows)

postgres=# \q

Happy coding!