How to Install Postgres on Ubuntu 20.04 in WSL
This is a post on how to install Postgres on Ubuntu 20.04, on Windows Subsystem for Linux (WSL). This should hopefully be a straightforward installation for you, which is done by following these 3 steps:
# Update Local Packages on Ubuntu in WSL
# Install Postgres on Ubuntu
# Restart Postgres Service on Ubuntu
Update Local Packages on Ubuntu in WSL
First, we need to update our local packages, by running the following apt command:
# update local packages sudo apt update

Install Postgres on Ubuntu
The next command will install Postgres. We’re including the ‘-contrib‘ package which will give us extra functionalities.
# install postgres on ubuntu sudo apt install postgresql postgresql-contrib

Once the installation completes, we can enter psql using the ‘postgres’ user that was automatically created during the installation.
# login to psql with the out of box postgres user sudo -u postgres psql \q (to quit back to terminal)

Restart Postgres Service on Ubuntu
You may need to restart the Postgres services after the installation to overcome an error. You can do this by running the following:
# restart postgres service ubuntu sudo service postgresql restart
