How to setup WSL2 and run Linux GUI apps in Windows operating system
Published: 2022-04-01 18:25:24

Windows Subsystem for Linux (WSL) is a Windows tool that allows developers run a GNU/Linux environment, install packages from the Ubuntu and other Linux archive, and run Linux applications and workflows directly on Windows, unmodified, without the overhead of a traditional virtual machine or dual-boot setup.

# Installing WSL2  

There are two ways by which we can install wsl2 in windows operating system and this depends on your windows version and build number.
To check your windows version:

Press <kbd>WIN</kbd> + <kbd>R</Kbd> , type **winver** and then press <kbd>ENTER</kbd> .

## First Method (Easy Method)

**Prerequisites** : You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11.

1\. First we have to open a command prompt with administrator privileges.    
Select Start, type **PowerShell**, right-click **Windows PowerShell**, and then select **Run as administrator**.

![step 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vb3k4x347cnfkn9ju3mn.png)

2\. Run this command : `wsl --install`
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q7e3zhqzxc31oqzxnjk8.png)  
This command will enable the required components, download the latest Linux kernal, set WSL 2 as default and install a Ubuntu (by default) distribution.
Only thing your have to do now is to set new Username and Password for your newly installed Ubuntu. 

> This above command will only works if you are installing WSL for first time and WSL is not installed at your PC at all. 

If this method don't work for you then follow the next step.

3\. Check the list of available Linux distributins available to download from the online store. To do so, run this command :
`wsl --list --online` or `wsl -l -o` .

![list of linux distro](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ew6vwfr86r3ctzn7lkx8.png)

4\. Run this command to install your desired Linux Distribution: `wsl --install -d <Distribution name>`

> Here : `<Distribution name>` should be same as one that   one mention in **NAME** section.
> 
> For example, suppose I want to install Debian then i have to run this command : `wsl --install -d Debian`  
> ![wsl --install -d Debian](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/koegyxe1aaemmz09v0si.png)

5\. Once the WSL install is completed your will need to set **user account** and **password** for your newly install Linux distribution.
![setting user profile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bkd9lstgwcuwkg5ni4l.png)

Once everything is all done, close the terminal.
To open the installed Linux Distribution: 
Select Start, type **<Distribution Name>**, and then Select  and Run.

---

## Second Method (Manual Method)

This method is more those computer which are running an older build of windows.

Step 1: Open PowerShell as Administrator (Start menu > PowerShell > right-click > Run as Administrator) and run this command :
```powershell
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
```
This will enable the Windows System for Linux feature.

Step 2 : Enable Virtual Machine feature by running this command :
```powershell
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
```

Step 3 : Restart the system and then run this command in PowerShell as Administrator.

```powershell
wsl --set-deafult-version 2
```

Step 4 : **Installing a Linux Distribution for your choice**.

Open the Microsoft Store[](https://aka.ms/wslstore) and select your favorite Linux Distribution. Here are following links for distribution available in Microsoft Store.

- [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 12 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 Enterprice](https://www.microsoft.com/store/apps/9N8LP0X93VCP)
- [Alpine WSL](https://www.microsoft.com/store/apps/9p804crf0395)
- [Raft](https://www.microsoft.com/store/apps/9msmjqd017x7)

![UBUNTU](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xtll5yovowop73u9kmsg.png)
 
Step 5 : Once the Linux distribution of your choice is downloaded from Microsoft office. Open  a newly installed Linux distribution, this will take you to Terminal window where rest of the installation will finish. This process will take a few minutes.

You will then need to create a user account and password for your new Linux distribution.

With this, You have successfully set up WSL2 in your windows machine.

## Extra
- **To check list of all Linux Distribution and check which version for WSL it is running.**
 Use this command in PowerShell : `wsl -l -v`

- **To update from WSL 1 to WSL 2 on previously installed Linux distributions**
Use this command : `wsl --set-version <distro name> 2`

- **To set the default Linux Distribution**
Use this command : `wsl -s <DistributionName>` or `wsl --setdefault <DistributionName>`

---  

## Run Linux GUI Apps

Prerequisites : 
- Windows 11 Build 22000 or higher
- Installed driver for vGPU
- Linux GUI apps are only supported with WSL 2 

If you just set-up WSL by using above methods, you're already ready to begin using Linux GUI apps on WSL!

> #### For Existing WSL install
> 1\. Open a command prompt/PowerShell as administrator.
> 2\. Update the WSL
> ```powershell
> wsl --update
> ```
> 3\. Shutdown the WSL by running this command
> ```powershell
> wsl --shutdown
> ```  
---
#### Update the packages in your distribution
Run this command : 
```bash
sudo apt update
```  
  
#### Installing and running GUI-Apps in your distribution
Command for installing a package : `sudo apt install <package-name>`
Command to launch the package : `<package name>`

> Now, lets install and launch Firefox. To do so, use this command `sudo apt install firefox`
> ```bash
> sudo apt install firefox
> ```
> This may some time depending upon your Internet Speed.
> ```bash
> firefox
> ```
> ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ph27rciwblv0ydwww611.png)

___

Thank you being with me and reading my article. If you like my post, follow me on Dev.to and do connect with me on [LinkedIn](https://www.linkedin.com/in/kumarsubroto) and [GitHub](https://www.github.com/subrotokumar)