How to setup WSL 2 for VS Code and Node.js development (2021)
Tags: node, vscode, wsl, webdev
Published: 2020-09-11 07:52:01

![Code_-_Insiders_Hqq4ON4eDV](https://dev-to-uploads.s3.amazonaws.com/i/fmw2v65l7io1fuaeyh0a.png) 

This quick guide will demonstrate how to install the new Windows Subsystem for Linux (WSL) 2.

WSL enables Windows users to run GNU/Linux environment under a Windows host machine. No more virtual machines or dualbooting!

*Note: The guide is written using Ubuntu as the Linux distribution, you may need to tweak the shell commands if want to use a different distro.*

<hr>

## Prerequisites

* Windows version 1903 or higher (Build 18362 or higher for x64 systems)

ℹ️ Press Win+R and type in `winver` to find your version.

<hr>

## WSL 2 setup

Run following commands with **elevated** PowerShell.

#### Installing WSL 2

&#8291;1. Install WSL 1

```powershell
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
```

&#8291;2. Enable the "Virtual Machine Platform" optional feature.

```powershell
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
```

&#8291;3. Restart your machine.

&#8291;4. After restarting set your WSL version to 2:

```powershell
wsl --set-default-version 2
```



#### Picking distro

Go to the Microsoft store and pick & install distro you like. I chose [Ubuntu 20.04 LTS](https://www.microsoft.com/store/apps/9pjn388hp8c9).

The following Linux distributions are available as of now (10th Sep. 2020):

{% details Full list of distributions %}
* [Ubuntu 16.04 LTS](https://www.microsoft.com/store/apps/9pjn388hp8c9)
* [Ubuntu 18.04 LTS](https://www.microsoft.com/store/apps/9N9TNGVNDL3Q)
* [Ubuntu 20.04 LTS](https://www.microsoft.com/store/apps/9n6svws3rx71)
* [openSUSE Leap 15.1](https://www.microsoft.com/store/apps/9NJFZK00FGKV)
* [SUSE Linux Enterprise Server 12 SP5](https://www.microsoft.com/store/apps/9MZ3D1TRP8T1)
* [SUSE Linux Enterprise Server 15 SP1](https://www.microsoft.com/store/apps/9PN498VPMF3Z)
* [Kali Linux](https://www.microsoft.com/store/apps/9PKR34TNCV07)
* [Debian GNU/Linux](https://www.microsoft.com/store/apps/9MSVKQC78PK6)
* [Fedora Remix for WSL](https://www.microsoft.com/store/apps/9n6gdm4k2hnc)
* [Pengwin](https://www.microsoft.com/store/apps/9NV1GV1PXZ6P)
* [Pengwin Enterprise](https://www.microsoft.com/store/apps/9N8LP0X93VCP)
* [Alpine WSL](https://www.microsoft.com/store/apps/9p804crf0395)
</details>
{% enddetails %}

There are also 3rd party distributions for WSL available. [ArchWSL](https://github.com/yuk7/ArchWSL) is one of them.

<hr>

## Installing Node.js for WSL

😕 I ran into issues using NVM with WSL, we'll be installing Node.js the manual way.

&#8291;1. Open WSL by hitting Win+R and typing: `wsl`

&#8291;2. Run following commands (You may want to up the version number):

```bash
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
```

&#8291;3. You can verify the installation by typing `node -v`

<hr>

## Setting up VS Code

1. Install [Remote - WSL](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl) extension.

2. Press the icon on bottom left to start new WSL session

    ![firefox_bxmCokZGiH](https://dev-to-uploads.s3.amazonaws.com/i/u3tottj024nw7nuvllta.png)

3. That's it! :)

<hr>

## Bonus :star: 

#### Install `yarn`

```bash
sudo npm i -g yarn
```

#### Install `ohmyzsh`

```bash
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
```

You also need to change the default VS Code shell, press Ctrl+Shift+P:

![Code_-_Insiders_UIwhZNweek](https://dev-to-uploads.s3.amazonaws.com/i/qokrx4sjdaf2n3ikmuka.png)
![Code_-_Insiders_mKcIgqE13e](https://dev-to-uploads.s3.amazonaws.com/i/e3qvzrcin8atat3ndp49.png)