Developing for Linux in Windows 10 with WSL 2 - Part 1
Tags: ubuntu, vscode, dotnet, wsl2
Published: 2020-11-15 17:25:18

## Background

Most of the open source software's are developed for Linux distros and this makes it difficult to run on Windows. Of course you can run a Ubuntu VM on Hyper-V or Virtual Box and install your development environment on the machine as you would on a regular machine.

However to run the VM's on your machine your machine should have enough juice to run the VM's smoothly and its not seamless either if you want to transfer files between your Windows host and your VM. You can also setup dual boot with Windows 10 and Linux, however maintaining different operating systems on a machine is a pain.

With WSL, installing Linux distros in Windows 10 is as easy as installing a app. You can share files easily between Windows and your Linux distro and you can also develop for Linux right inside Windows 10. 

### But I already have WSL1, can I upgrade?
Sure you can upgrade from WSL1 to WSL2, you can refer my [post](https://dev.to/adityakanekar/upgrading-from-wsl1-to-wsl2-1fl9) to upgrade from WSL1 to WSL2.

### Windows Subsystem for Linux (WSL)

Most of you might have heard of Windows Sub-system for Linux AKA WSL. What it enables you to do is install Linux distros on your Windows 10 machine like a app from Windows 10. Yes, you heard it right install distros as app. However things are not that simpler if you have Windows 10 Home Edition since WSL uses Hyper-V to run a VM behind the scenes. The other problem is Docker or MicroK8S are not supported on WSL and this was a bit of a downer. However it was a step in the right direction from Microsoft.

### WSL 2
Microsoft has resolved most of the issues which were bugging WSL with WSL 2. WSL 2 does uses VM behind the scenes but its managed, also it uses full Linux Kernel built by Microsoft unlike WSL. You can learn more about WSL here,

https://docs.microsoft.com/en-us/windows/wsl/compare-versions

## Pre-Requisites

### Installing / Upgrading WSL 2

You can refer the instructions for installing WSL 2 on the official Microsoft site. 

https://docs.microsoft.com/en-us/windows/wsl/install-win10

### VS Code

I will be using VS Code for this article and its my choice of IDE for development (I am obsessed with VS Code :p) 

https://code.visualstudio.com/download

Install following plugins,
1. Remote WSL

### Windows Terminal Preview - Optional

You can install Windows Terminal from here. This step is not necessary, however I will recommend you to try it.

https://www.microsoft.com/en-in/p/windows-terminal-preview/9n8g5rfz9xk3?rtc=1&activetab=pivot:overviewtab

## Install Linux Distro from Windows store

For this article I have install Ubuntu 20.04LTS from Windows Store. Assuming you have completed above steps for installing WSL 2 on your machine. This step should be straightforward. Jut got to your Windows Store and search for Ubuntu. Install Ubuntu 20.04LTS.

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

Once you install, search for Ubuntu in your Windows Search bar and click it. 

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

Since the app is being launched for the first time, just follow the installation steps. After installation you will be asked to create username and password, give username and password of your choice and you are all set. 


### Launching Ubuntu  

Assuming you have completed all the steps, just search for Ubuntu or if you have installed Windows Terminal, select the shell you want to open as shown below,

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

### Listing installed distros

Run following command in Powershell or command prompt to display all installed distros,

```
wsl -l -v
```
You should be able to see similar output as shown below,

```
 NAME                   STATE           VERSION
* docker-desktop         Running         2
  Ubuntu-20.04           Stopped         2
  docker-desktop-data    Stopped         2
```

In the next [part](https://dev.to/adityakanekar/developing-for-linux-in-windows-10-part-2-1ndl) we will create a sample dotnet core console app and debug it in Windows 10 while developing on Ubuntu-20.04.

Till then, Happy Coding !