Urgent.News

What's breaking now, across thousands of outlets.

Tech

From Zero to Hero on psql: My Weekend Adventure Installing PostgreSQL on WSL ๐Ÿง๐Ÿ˜

Hey folks! ๐Ÿ‘‹ So here's the deal โ€” last weekend I decided I was done fighting with database installers that never quite worked right on Windows. A senior dev friend of mine said, "just use WSL and run it like you're on a real Linux box," and honestly? Best advice I got all semester. So grab your coffee (or chai, no judgment โ˜•), and let's walk through this together, step by step, exactly how I didโ€ฆ

Hey there! So, I had a weekend adventure installing PostgreSQL on Windows Subsystem for Linux (WSL). My senior dev friend recommended using WSL for a real Linux environment, and I'm thrilled I took their advice. Here's how I did it:

1. What is WSL?

WSL stands for Windows Subsystem for Linux. It's Microsoft's way of running a real Linux kernel inside Windows without needing a dual boot or virtual machine. This is perfect for backend development, databases, and DevOps.

2. Installing WSL

Installing WSL is as easy as running a one-liner in PowerShell as an administrator. Type `wsl --install`, hit Enter, and let it install. After a restart, launch Ubuntu from your Start Menu. Remember, your Ubuntu login is separate from your Windows account.

3. Update Ubuntu

Inside Ubuntu, run `sudo apt update && sudo apt upgrade -y`. This refreshes the package lists and updates existing software. It might take a few minutes, perfect for a coffee break.

4. Install PostgreSQL

Now for the main event: PostgreSQL. Install it with `sudo apt install postgresql postgresql-contrib -y`. Start the PostgreSQL service with `sudo service postgresql start` and verify it's running with `sudo service postgresql status`.

5. Meet postgres

When PostgreSQL installs, it creates a Linux system user called 'postgres' and a PostgreSQL database role also named 'postgres'. This 'postgres' role is the superuser of your database, with full administrative rights.

6. Log into psql

psql is PostgreSQL's command-line interface. Log in as the superuser with `sudo -i -u postgres psql`. Your terminal prompt should now say 'postgres=#'. To exit, type `\q`.

7. Create Your Own User

It's a good practice not to live as 'postgres' forever. While still logged in as 'postgres', create your own user: `CREATE USER student_dev WITH PASSWORD 'yourStrongPassword123';`. Replace 'student_dev' with your desired username and choose a secure password.

Written by urgent.news from Dev.to's reporting โ€” not their text. Machine-written โ€” may contain errors; check the original before relying on it.

Read the original at dev.to โ†’

More in Tech

Linkind Smart Light Stick Wins Our Best Smart Lighting Award

Smart lighting is at its most useful when it does more than introduce a few fun colors. It should make a space more comfortable during an ordinary evening, add energy when the occasion calls for it, and remain easy enough that everyone in the household can enjoy it. The Linkind Smart Light Stick Color+White 850lm [โ€ฆ]

More from Thursday 3 September โ†’