A super detailed beginner-friendly walk-through
Why install PostgreSQL on WSL 2?
Simply because the installation of PostgreSQL on Windows is kind of a pain, and I also use WSL 2 for other development tasks. You can visit my previous post on how to set up WSL 2.
I tried to download from the official website and install PostgreSQL 13.1 for Windows x86–64, and this was the error I couldn’t get rid of — Unable to write inside TEMP environment variable path.
After googling, I found a post that might be helpful for others, but it didn’t solve my problem. I was told to download 3rd party distributions and find a standalone version of PostgreSQL, and this installer works for me. This is the workaround if you have experienced the same issue but still want to install it on Windows.
Install PostgreSQL on WSL 2
Here comes the WSL 2, much easier, and you can visit the Windows WSL documentation for more detail.
- Open your WSL terminal (ie. Ubuntu 18.04).
- Update your Ubuntu packages:
sudo apt update
- Once the packages have updated, install PostgreSQL (and the -contrib package which has some helpful utilities) with:
sudo apt install postgresql postgresql-contrib
- Confirm the installation and get the version number:
There are 3 commands you need to know once PostgreSQL is installed:
sudo service postgresql statusfor checking the status of your database.
sudo service postgresql startto start running your database.
sudo service postgresql stopto stop running your database.
The default admin user,
postgres, needs a password assigned in order to connect to a database. To set a password:
- Enter the command:
sudo passwd postgres
- You will get a prompt to enter your new password.
- Close and reopen…