Run Linux on Windows with WSL 2 & VS Code
Tags: javascript, typescript, windows, linux
Published: 2022-02-06 13:53:42

---
title: Run Linux on Windows with WSL 2 & VS Code
published: true
description: 
tags: javascript, typescript, windows, linux
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vtbkwzn15btbtmsc2jl2.png
---
The [Windows Subsystem for Linux](https://docs.microsoft.com/windows/wsl/) 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.
<!--more-->
## 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](https://typescript.tv/hands-on/docker-desktop-hardware-assisted-virtualization/#Enable-Microsoft-Hyper-V). If these two conditions are met, you can proceed. 

The following post is based on my video:

{% youtube bRW5r7TK6KM %}

## Install WSL 2 💾

1. Open Windows PowerShell
1. Execute `wsl --install`
1. 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cbi04bbujbdvp751or4m.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pxl69tb9w8m4gkaqi0a4.png)

## 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)
1. Open File Explorer ("Win" + "E")
1. Enter `\\wsl$` in the address bar

**Screenshot:**

![WSL in Windows Network](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tebmbe20by8ljgx6f9vs.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/10ul7n0gz5hipbnhhea0.png)

## 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](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ivdfo5fvghyxfmf6lhq.png)

## Use Docker with WSL 2 🐳

You don't have to reinstall Docker on your Linux installation. [Docker Desktop for Windows](https://hub.docker.com/editions/community/docker-ce-desktop-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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2duajxn0hdimfhdtqrho.png)

## Run Linux GUI apps 🎨

If you have Windows 11 (Build 22000 and higher) installed, then you can also [run Linux GUI apps](https://docs.microsoft.com/en-us/windows/wsl/tutorials/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](https://twitter.com/bennycode) or [subscribe to my YouTube channel](https://www.youtube.com/c/typescripttv) if you liked this post. I would love to hear from you what you are building. 🙂 Best, Benny