Setting up Windows Subsystem for Linux (WSL 2) as a Bootcamp Grad
Tags: windows, wsl, webdev, programming
Published: 2020-07-01 21:16:54

#### NOTE: This post will be updated as time goes on with further tips, and if the installation process changes in any way.

***

If you're anything like me, then you're a developer with a love for (or at the very least a respect for) all different kinds of modern operating systems. They all provide their own unique user experiences, and all have something to offer for different people.

However, if you're also like me, you may have finished up a programming bootcamp where it was made clear that MacOS is the preferred OS environment for web development, and that using Windows would lead to a world of headaches and compatibility issues.

While I love both MacOS and Windows equally for different reasons, I understood why:

* MacOS has the benefit of a built in terminal to interact with its file system.
* MacOS is built on a [Unix](https://en.wikipedia.org/wiki/Unix) kernel, upon which most frameworks and languages built for web development work seamlessly.
* MacOS has [Homebrew](https://brew.sh/), a package manager that uses terminal commands to install and use open-source software.

Windows does not function on a Unix kernel, and has its own completely different set of file structures and developer tools. This isn't inherently bad, and is quite good for some other programming endeavors, but is less effective for modern web development that makes consistent use of packages and servers.

***

Enter Linux, and more specifically Windows Subsystem for Linux.

Linux is an open-source Unix operating system that comes in all sorts of different flavors and varieties known as *distros*, all of which have roughly the same core benefits for web development. They differ from MacOS in a large number of ways, but at their lowest levels offer comparable and equally efficient development experiences.

It used to be that, in order to get access to a Linux development environment on a Windows machine, you had to either install a full Linux distro alongside your Windows installation (known as dual-booting or [multi-booting](https://en.wikipedia.org/wiki/Multi-booting)), or install Linux inside of a [virtual machine](https://en.wikipedia.org/wiki/Virtual_machine) or VM, essentially a sandboxed instance of that operating system running in a window within your main operating system.

However, in 2016 Microsoft introduced [Windows Subsystem for Linux](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux), a compatibility layer that allowed Linux executables and command line interfaces to be run within Windows 10. Then, in 2019, Microsoft introduced **WSL 2**, a full fledged Linux kernel operating in a lightweight and efficient virtual machine natively through Windows (and the version we'll be going over in this post.)

The benefits of using WSL are many, but the fundamental benefit is that you can now have **an entire, native Unix development environment and filesystem built into your Windows installation**, allowing quick and easy access to your development files and a full fledged terminal and command line, while also having your native Windows programs, games and functionality immediately available. Cool stuff, right?

***

Let's begin our installation by following the core steps listed on [Microsoft's own website](https://docs.microsoft.com/en-us/windows/wsl/install-win10):

### **Install the Windows Subsystem for Linux**

Open Powershell.exe as an administrator and run:

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


### **Update WSL installation to WSL 2**

Make sure your Windows installation is at at least version 2004, Build 19041 or higher (which can be checked by pressing **Windows logo key + R, type winver, then selecting OK**.

Now, make sure that the optional "Virtual Machine Platform" is activated by going back into your Powershell.exe instance and typing:

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

Now restart your computer to complete the update to WSL 2!

### **Set WSL 2 as your default version**

Open Powershell.exe back up, and type:

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

You might get an error along the lines of
> WSL 2 requires an update to its kernel component. For information please visit https://aka.ms/wsl2kernel

If so, visit the link provided in the error and install the provided kernel, then run the command again.

### **Install a Linux distribution**

Now, open up the Microsoft Store app on your computer, and search your a Linux distribution.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/6911iktdzgyg12849h7z.png)

In this situation I would advise installing **Ubuntu**, as it's one of the more user-friendly, stable and accessible versions of Linux available. Choose the version that just says *Ubuntu* without any version numbers, as this will automatically install the most up-to-date stable version of the OS.

### **Set up your distribution**

Now, open up the newly installed *Ubuntu* app on your computer, and a new terminal should open. It will take some time to do an initial install, and then ask you to set up your username and password for the Linux install (**note:** this is different than your Windows username and password, although you can use the same ones here as well if you'd like.)

Take one more moment to type the following into your Linux terminal to upgrade your installation's packages to their latest versions:

```
sudo apt update && sudo apt upgrade
```

And congratulations, you're now officially set up with WSL 2 on your Windows 10 machine! Let's move on to some further tips and pieces of information that you should know when coming from MacOS. At this point you can essentially use the Linux terminal to continue your development 

***

## Where are these files being stored, anyway?

The virtual machine containing all of your newly created Linux files can be found either by typing the following into your Linux terminal to open up a Windows file explorer at that location:

```
explorer.exe .
```

Or by searching for the following in your Windows file explorer:

```
\\wsl$\Ubuntu\home\*your-username*
```

These files are connected to your Windows installation as a network drive and are fully accessible through Windows' interface, but are saved in a different file structure. I would recommend **adding this folder to your Quick Access menu** on the side of your file explorer for easy access.

Previously in WSL 1 it was faster to save your development files in your Windows filesystem, but with WSL 2 you will see an improvement in I/O performance by keeping all of your development files exclusively in this Linux directory.

The advantage of this is that you have a filesystem and installation entirely devoted to development, safely sandboxed off from the rest of your computer. If something goes wrong, or you need to delete it and reclaim hard drive space from projects and packages, it's an easy process.

***

## What Terminal should I use?

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/l3lgbsdyzhplo1vl1quh.png)

Since WSL lacks a GUI (for now), you'll be doing most things on the command line. This is very good practice in the long run since being confident on the command line is one of the hallmarks of an experienced developer.

You can continue to use the installed Ubuntu (or other distro) app as your dedicated terminal, OR you may install the newly released and well regarded [Windows Terminal](https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701?activetab=pivot:overviewtab) from the Microsoft App Store.

The Windows Terminal is open-source and configurable, although understanding how to make changes to the settings can be a bit tricky as it requires editing a JSON file.

The most important basic change to make is setting the default shell that it opens into to your WSL installation. You can do this by opening the settings from the Terminal menu bar, then going through your list of "profiles" to find the one matching your Ubuntu/WSL install and copying the "guid" value:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/58op1tozr8dhtkkahkiq.jpg)

Then pasting it into the "defaultProfile" value at the top of the file:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cew0bcohdezseyd2ua53.jpg)

And you're done! There are plenty of other settings and themes to experiment with, and I recommend reading through some of the [official documentation](https://docs.microsoft.com/en-us/windows/terminal/) on the subject.

***

## What editor/IDE should I use?

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/09npn4ovr0yjd8p61xxq.png)

This is a question that comes down to preference, but there's one main option to pick that outweighs the others due to pure compatibility: [Visual Studio Code](https://code.visualstudio.com/)

VSCode is an open source code editor from Microsoft, and features excellent WSL integration.

First off, install VSCode on your Windows machine as you would for any other application or program. Then, once you've installed and set it up initially, install the [**Remote - WSL**](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl) extension.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/nha1796usojmhpr285xv.jpg)

This allows you to use VSCode's graphical interface as a regular Windows application, while it actually opens up and does all of its logic inside of your Linux installation. It should work smoothly for all of your Linux development files, and will allow you to utilize the integrated terminal in VSCode in addition to your Windows Terminal/Ubuntu apps.

You should also be able to type the following from a Linux directory to open it in VSCode:

```
code .
```

***

## More to come

That's it for right now, though I'll be returning to this blog post later on to add more tips and tricks for WSL users, especially those switching from MacOS. Thanks for reading!