DEV Community

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

Posted on

12 1

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

Runner H image

The Automated Opportunity Scout: How Runner H Became My Personal Business Analyst

Check out this winning submission to the Runner H "AI Agent Prompting" Challenge. ๐Ÿ‘€

Read more โ†’

Top comments (0)

Gen AI apps are built with MongoDB Atlas

Gen AI apps are built with MongoDB Atlas

MongoDB Atlas is the developer-friendly database for building, scaling, and running gen AI & LLM appsโ€”no separate vector DB needed. Enjoy native vector search, 115+ regions, and flexible document modeling. Build AI faster, all in one place.

Start Free

Join the Algolia MCP Server Challenge: $3,000 in Prizes!

Explore the intersection of AI and search technology by building with the Algoliaโ€™s MCP Server. Three talented winners will be selected to share in our $3,000 prize pool!

Check out the challenge

DEV is bringing live events to the community. Dismiss if you're not interested. โค๏ธ