Developing on Windows: WSL2, Ubuntu, Windows Terminal, VS Code, npm Installation Tips (now with Flask Server stuff!)

Photo by Sharon McCutcheon on Unsplash

Good evening. It’s February 12, 2021, and I’m using this guide to set up my personal development environment on Windows 10. I’m updating this as I go if I find something has changed.

Initially I had to do this because I found that my Ubuntu — Postgres apps weren’t connecting locally, and couldn’t for the life of me figure out what was going wrong. I went back to the drawing board and found out I had to do things differently. So, here’s what I did.

First, these instructions are vital to follow. That is, read them thoroughly, and follow each step. They will make sure your Windows build is the right one so that your WSL and WSL2 installations work.

Windows also has a very handy and useful new Terminal that is quite awesome:

I also wanted my Ubuntu install to appear first — not Powershell. To do that, edit the settings in Windows Terminal (it will open a .json text file), you will want to change the line “defaultProfile”: “{c6ea...your own numbers here}” to have “defaultProfile”: “find the 'guid' for your Ubuntu install and put it here” .

I also wanted my Ubuntu Linux command line to start at my Linux root directory rather than my Windows root, so in the Ubuntu object I added: “startingDirectory”: “//wsl$/Ubuntu/home/username/”.

I found this to still be very useful for customizing Windows Terminal the way I wanted:

Lastly, it turns out you don’t have to install VS Code in your Linux command line anymore. You can simply install it in Windows and it will be available using your Terminal when you edit it. Here are instructions:

Running Visual Studio Code on Windows

Lastly, I wanted to start up a quick create-react-app instance to do a personal project, but I came into trouble trying to use npx create-react-app. It turns out that npm wasn’t install or wasincorrectly installed. Came upon these three commands which then allowed me to use npx as I wished.

sudo apt-get updatesudo apt-get upgradesudo apt install npm

Hope this pointed you in a good direction! Good luck with your projects!

Making a Flask Server with WSL2

Setting up Flask for Python is supposed to be easy, and you are supposed to get a flask server up and running in no time. But if you have WSL2 installed, you might be caught off guard, and find that even though your flask server is running in your bash terminal, when you try to connect to it with a web browser, you can’t get it to connect to your localhost.

I found that WSL2 changes somethings, and while my current understanding of why localhost doesn’t work the same way when you try to access your localhost with a Windows web browser, this helped me:

Accessing Linux networking apps from Windows (localhost)

So, if I tried to run a Flask server with what most tutorials mention (letting the application choose the localhost ip address), it didn’t work, So, a basic application needs to look more like:

from flask import Flask
app = Flask(__name__)
@app.route("/")
def welcome():
return 'Welcome to my application!'
if __name__ == '__main__':
app.run(host='put the IP address of the Linux host VM')

Ok, so you can do that, or another solution is to update your Windows to the most recent version, and then the local host will work as expected in most tutorials.

Photo by Fotis Fotopoulos on Unsplash

Physicist turned Actress turned Writer turned Teacher turned Engineer. Speaker of uncomfortable truths and lover of animals, gaming, and JavaScript.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store