How to run Linux bash in Windows OS
Tags: beginners, linux, programming, webdev
Published: 2021-04-09 17:22:48

---
title: How to run Linux bash in Windows OS
published: true
description: Windows Subsystem for Linux (WSL)
tags: beginners, linux, programming, webdev
//cover_image: ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sg6v38y2ijcaibr9ubrx.png)
canonical_url: https://sameerkatija.medium.com/how-to-run-linux-bash-in-windows-os-f861ff8aacc0
---
I use windows for most of my daily tasks, and almost all the software I prefer for my daily tasks, are windows based. Almost 90% of my time is spent on Windows, but still, the gap is there which can only be filled by Linux. Being a developer, I needed Linux for most of my tasks, one of them is deployment. Unlike Windows, Linux is free and most of the Linux versions are open-source.

As the need for Linux came, I completely made a shift to ubuntu. After shifting, I realize that there are plenty of reasons I should shift back to windows. Well, my favorite software which I used in my free time was missing there especially Adobe illustrator(I seriously love this software and this lets you explore your creativity). I came back to windows and opted for the virtual machine.

Think of a Virtual machine as a machine inside your real machine. It’s basically a concept, where most of the resources are split and are made available as a new virtual machine, though this new machine is totally virtual and acts as a real machine. This new virtual machine can be used to install another OS inside your main machine. I hope that now you have a concept of the virtual machine but as a reference, you can also read this definition by [Wikipedia](https://en.wikipedia.org/wiki/Virtual_machine).

>In computing, a virtual machine is the virtualization/emulation of a computer system. Virtual machines are based on computer architectures and provide functionality of a physical computer. Their implementations may involve specialized hardware, software, or a combination.

Virtual Machine is better when it comes to dual boot. As every tool has some flaws too. Virtual machine too has some cons. As I alluded, a virtual machine runs on your real machine. So each and every hardware resource which our virtual machine will need have to request from the main machine. It means that our main machine will access hardware indirectly, thus its performance will be impacted. So, what is the alternative which can be the best fit for our needs? It’s Windows Subsystem for Linux (WSL).

## What is Windows Subsystem for Linux(WSL)

The WSL is a type of resource within windows OS that allows users to run a Linux command-line interface(CLI) in windows. In WSL, you can do almost all the tasks which you can perform on Linux Terminal.

WSL is based on a Virtual machine. When we download a preferred Linux distro, we are not creating a VM instance. Instead, WSL provides a layer for translating Linux system calls to Windows system calls. Thus Linux binaries are able to run in windows unmodified. We can also have the Linux process communicate with Windows Process. WSL also maps Windows services, like the filesystem and networking, as devices that Linux can access.

## Why WSL is better than Virtual Machine

Instead of using a VM instance, WSL virtualizes a Linux kernel interface on top of the Windows kernel. it means that running WSL only requires a small amount of memory. And when it’s not in use, the WSL driver isn’t loaded into memory, making it much more efficient than a solution based on a VM.

## How to setup and install WSL

In order to use WSL in windows, you have to set up and install it first to do that we need some configuration and some Linux kernel installed in our machine, Don’t worry this isn’t as tedious as it sounds.

### Step 1 — Enable the WSL

WSL is a Windows feature and it is by default off and to enable it you need to open `powershell` as administrator and run the following command

```shell
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
```
### Step 2 — Enable Virtual machine features

After enabling the WSL feature then we need to enable virtualization functionality to run WSL on windows. In order to enable VM features on your machine, you need to run the command given below in Powershell.

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

### Step 3 — Download Linux Kernal Package

Now, you need to download the Linux kernel package. you can download this package by clicking [here](https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi). or you can also download this package from [Microsoft's WSL documentation](https://docs.microsoft.com/en-us/windows/wsl/install-win10).

### Step 4 — Setting WSL2 as your current version

Open Powershell and run the command given below, you can skip this command. If you don’t want to work with WSL2, you can also work with WSL1. In my case, I would prefer to go for WSL2.

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

### Step 6 — Install your preferred Linux Distro

Open the [Microsoft store](https://www.microsoft.com/en-us/search?q=WSL) and search for your preferred Linux distro. I would suggest going for [ubuntu](https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6) because you will find a lot of community support in case you needed any help.

![Picture of Windows Store](https://miro.medium.com/max/875/1*v5G_1WRh8Om8nWsuRBZSyQ.png)

After installing, you need to open ubuntu and for the first time, you have to give a username and a password which will only be for ubuntu and will be used afterward to login and do other `sudo` stuff in ubuntu. With all that congrats on installing and setting up WSL on your machine.

## Conclusion

I am not against the dual boot, virtual machine instances, or anything else like that. I still use Virtual Machine for some of the Linux applications. The point I am trying to make in this article is that, if you need Linux to just fulfill your developer needs then WSL is the best choice to go for. If you still prefer some other tool and technology that’s totally fine. Choices are our own. With that thanks for reading this article and don’t forget to support me by clicking clap and sharing this with other developers. Cheers!