How to setup WSL 2 - The easy way
Tags: webdev, wsl, terminal
Published: 2020-06-07 19:48:46

WSL has become a popular choice tool of developmnet in Windows 10. With this tool you don't need to make a dual boot setup in your PC to have all the potencial of Linux because WSL gives you all what you need to start the developent ASAP, but of course WSL have some flaws like slow performance for I/O, slow file system mainly.

Microsoft released in the last main update for Windows 10 (Release 2004, build 19041 or newer) the new version of WSL, WSL 2.

## But why WSL 2?

The main feature of WSL 2 is giving a better performace comparing it with WSL 1, MS did a great work that they boosted up to 20x times than the original version (that's a lot! 🤯), and of course there are many features like:

- Full System Call Compatibility
- Small memory usage
- Accesing to WSL files in Windows Explorer though the network section
- And mainly, Full Linux Kernal

## What do I need to run WSL 2?

As I said before, you need to have **Windows 10 Release 2004 Build 19041 or newer** and any other Windows 10 than Windows 10 S according to MS.

## Installation

First, we need to enable as usual WSL into out system and Hyper-V, a virtualization tool from Microsoft, this VM tool is needed because WSL 2 works as a kind of Virtual Machine, but in the unique way from Microsoft (this is where the magic happens)

Press the **Windows** key and type *features* and select: **Activate or deactivate Windows features**

![Activate or deactivate Windows features](https://dev-to-uploads.s3.amazonaws.com/i/bgo9y62uaw44ygn8zw2b.png)

An small windows with a list of features available for our system, we need to look for **Hyper-V** and **Windows Subsystem for Linux**, scroll through the list and check both options.

![Hyper-V option](https://dev-to-uploads.s3.amazonaws.com/i/296m3usppatl5f9n6t2m.png)

![WSL option](https://dev-to-uploads.s3.amazonaws.com/i/cjpeine4te09nhdrn077.png)

After both options are checked, press Accept (or OK, sorry for the spanish). Windows will start downloading the files needed, after it finishes, it will propmt to you to Restart your machine, accept the restart.

Once your machine restarted, you are ready to download Ubuntu from the Microsoft Store, search it through the Windows Store or from this [link](https://www.microsoft.com/es-us/p/ubuntu/9nblggh4msv6?activetab=pivot:overviewtab). Once the download is done, run the app, wait until the installation is ready and setup your user, we are almost done.

As you can see, this is the normal process from WSL 1, but this is the aditional step we need to do, open up **Powershell** and type: **wsl --list --verbose**, running this command should list your distro as:

```cmd
Distro Status  Version
Ubuntu Stopped 1
```

As you can see, we still have WSL 1 being selected for our distro, to setup WSL 2 we need to run this command: `wsl --set-version <your-distro-name> 2`, using the example should be: `wsl --set-version Ubuntu 2`, it will show you a message that it will take some time to make the conversion to WSL 2, at this point you can do anything else like going for some coffee, stretch up your arms or legs, anything because it will some minutes (around 10-15 minutes).

Once the process is completed run once again the command: `wsl --list --verbose` or `wsl -l -v` as a shortcut, the list should display as

```cmd
Distro Status  Version
Ubuntu Stopped 2
```

And now we have WSL 2 ready to rock!

## Especial considerations

By using WSL 2 we need to have some special considerations:

- Don't use any app in Windows that uses Port 53, this port is needed by Hyper-V to have access to the internet and Windows, so if you have an app like Acrylic UI, this will prevent to WSL 2 start up running.
- If you are a Laravel developer, careful by installing `cpriego/valet-linux`, it will block your access to internet from your distro (I had some issues by trying to git pull a project until I found out it was the problem)

And that's it, is all for now, I hope this guide helps you with the process, see you next time around here.