DEV Community

Cover image for Run Linux on Windows with WSL 2 & VS Code
Benny Code for TypeScript TV

Posted on

Run Linux on Windows with WSL 2 & VS Code

The Windows Subsystem for Linux makes it easy to run a Linux environment on Windows. The integration is so seamless and powerful, that you can even connect VS Code to it and execute code automatically in a Linux terminal. With WSL 2 you no longer need Cygwin or MinGW.

Requirements 📝

To install the Windows Subsystem for Linux (WSL), you must have Windows 10 installed (Build 19041 and higher). WSL 2 also requires you to activate Microsoft Hyper-V. If these two conditions are met, you can proceed.

The following post is based on my video:

Install WSL 2 💾

  1. Open Windows PowerShell
  2. Execute wsl --install
  3. Verify your installation with wsl --status

Install Linux 🐧

WSL 2 allows you to install different Linux distributions (Ubuntu, Debian, Alpine Linux & others) from the Microsoft Store. Just open the "Microsoft Store" app and search for your favorite Linux version:

Debian on Microsoft Store

Start Linux on Windows 🏁

Once the Linux installation is complete, you can run it from the Windows Start menu. Here is an example running Ubuntu:

Run Ubuntu on Windows

Access Linux Files from Windows 📁

When you start your Linux distribution, all of its files become available in your Windows "Network". Here is how you can see your full Linux filesystem:

  1. Start Linux (Ubuntu app)
  2. Open File Explorer ("Win" + "E")
  3. Enter \\wsl$ in the address bar

Screenshot:

WSL in Windows Network

Access Windows Files from Linux 📁

You can also access your Windows NTFS filesystem from Linux. It works like this:

  1. Start Linux (Ubuntu app)
  2. Access your C:\ drive using cd /mnt/c

Screenshot:

Access Windows Files from Linux

Connect Visual Studio Code with Linux 🔗

By default, VS Code on Windows uses the Command Prompt when opening a Terminal. However, you can also run your code from your installed Linux environment. Here's how to do it:

  1. Install the Remote - WSL extension
  2. Click in the lower left corner of your VS Code and choose "New WSL Window using Distro..."
  3. A new VS Code window will open and use your Linux terminal by default

Screenshot:

Remote - WSL in VS Code

Use Docker with WSL 2 🐳

You don't have to reinstall Docker on your Linux installation. Docker Desktop for Windows allows you to use Docker from your Linux distribution. You just need to select "Enable integration with my default WSL distro" in "Settings" ➝ "Resources" ➝ "WSL Integration".

Screenshot:

Docker WSL Integration

Run Linux GUI apps 🎨

If you have Windows 11 (Build 22000 and higher) installed, then you can also run Linux GUI apps from your Windows system.

Closing Note ✍

I hope you are as impressed by the Windows Subsystem for Linux as I am. Please follow me on Twitter or subscribe to my YouTube channel if you liked this post. I would love to hear from you what you are building. 🙂 Best, Benny

Oldest comments (0)