DEV Community

Shaikh Al Amin
Shaikh Al Amin

Posted on • Edited on

2

How to setup postgres on ubuntu 20.04

Ref Link: Installation Docs

sudo apt install curl ca-certificates

sudo install -d /usr/share/postgresql-common/pgdg
sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc

sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'


// For AMD:

sudo sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt noble-pgdg main
" > /etc/apt/sources.list.d/pgdg.list'


sudo apt update

sudo apt install postgresql-13 postgresql-client-13
Enter fullscreen mode Exit fullscreen mode

Incase of i386 machine, we may need to update source list like below content:

Open the source list with gedit and add the content:

sudo gedit /etc/apt/sources.list.d/pgdg.list

deb [arch=amd64 signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt focal-pgdg main
Enter fullscreen mode Exit fullscreen mode

Login with postgres user and password:

sudo -i -u postgres
postgres@shaikh:~$ psql
postgres=# create database local_test;
CREATE DATABASE
postgres=# grant all privileges on database local_test to postgres;
GRANT
postgres=# ALTER USER postgres WITH PASSWORD 'postgres';
ALTER ROLE
postgres=# 
Enter fullscreen mode Exit fullscreen mode

Now login with postgres user:

psql -U postgres -h localhost

and password is postgres
Enter fullscreen mode Exit fullscreen mode

Give your career some juice. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay