Debugging WSL from VS Code

petermorlion profile image Peter Morlion Originally published at petermorlion.com ・2 min read

I love Visual Studio Code. I love the Windows Subsystem for Linux (WSL). Ever since I had to do Python development, I use the WSL for almost all of my non-.NET work: PHP, Python, Typescript/Node.js. That means running Visual Studio Code in Windows, but running the program in Linux. Up until now, I was missing one important feature: debugging support. Luckily, there’s an extension now.

Previously, I had to “debug” by adding console.log statements everywhere. Needless to say, this is not the most efficient way of debugging. I had to add statements, run the application, add more statements, run it again, rinse and repeat.

There is now an extension for VS Code that will allow you to debug applications running in the WSL. OK, it’s been around for a few months. Nevertheless, here’s a quick overview of getting started.

First, install the “Remote Development” extension in VS Code:

You could probably also install the “Remote – WSL” extension, but as I will probably be using the SSH extension as well, I’ll install the extension that contains the three separate ones: WSL, SSH and containers.

Then all you need to do is have a slight change in workflow. Instead of opening VS Code from the Start Menu (i.e. from Windows), you should start it from the WSL Terminal by running “code .” from the directory you wish to work in. This can be a Windows directory mounted in the WSL (i.e. “/mnt/c/…”) but it can also be a true Linux directory.

This last bit is interesting because this wan’t possible previously. If you wanted to edit something in your Linux user directory (“~/.gitconfig” for example), you had to edit it in the WSL. Using vim for example. Now you can do so in VS Code!

The first time you start VS Code from the WSL, it will install the necessary components:

After that, you’re good to go. VS Code will now perform all its actions in the WSL: sending commands, editing files, etc. However, this also means you might need to re-install some extensions. For example, my Cucumber extension (to provide syntax support in .feature files) had to be installed in WSL in order to work:

You can see you’re running a remote session by the green bar in the bottom left:

A consequence to keep in mind is that any output is now sent to the Debug Console in VS Code. If you were previously used to running everything in the WSL terminal in Windows, you’ll have to get used to this change.

Other than that, great work from Microsoft. It really makes everything just work. Happy debugging!

Posted on by:

petermorlion profile

Peter Morlion


I help organizations reduce bugs and release with confidence.


markdown guide