Setting Up WSL 2 in Windows 10

By Hiren Rupchandani & Mukesh Kumar

Table of Contents

What is WSL?

WSL stands for Windows Subsystem for Linux provided by Microsoft. It is a tool that helps us integrate and run any Linux distribution (such as Ubuntu) natively on Windows. It provides a hassle-free experience of using Linux by providing a Linux shell that can interact with the Windows file system.

How is it different than Virtual Box?

In VMs (Virtual Machines) like Virtual Box, we can run a multiple OS (Operating System) with certain amount of resources such as hard-drive space for a file system, some CPU cores, a chunk of RAM, etc. These resources are native to the Virtual Box OS and cannot be shared with the Windows file system or apps.

WSL uses fewer resources than a Virtual Machine. It does not provide a desktop-like interface, instead provides a command-line interface to run tools and apps alongside our Windows tools, desktop, and store apps. It also allows us to use Windows and Linux tools on the same set of files.

Why will you need WSL?

A simple answer is, many tools, languages, libraries are built for the Linux environments where they can have seamless communication with each other. Their Windows-ported versions are either unavailable or inefficient, which forces users to migrate between different operating systems. So WSL was created to address such issues and lets users use Bash and Linux command-line tools on Windows.

So now that we have a high-level overview of WSL, let’s see how we can set it up on a Windows 10 machine.

Prerequisites for WSL 2

The latest version of WSL is version 2. We will be installing Ubuntu as our Linux distribution for WSL 2. In order to install Ubuntu for WSL 2, you need a Windows Version 1903 or higher, with Build 18362 or higher.

To check your Windows 10 version, you can use the run command by pressing Win+R on your keyboard and writing winver inside the text box. Click on OK and you will see a pop-up with your OS details:

Windows 10 information with OS Version and Build

Setting Up Ubuntu as WSL

Now that our system is compatible to install Ubuntu as WSL, let us begin…

Step 1: Enable features on Windows 10

  • Click on search button or search bar on the taskbar.
Searching for “Turn Windows features on or off” in search bar
  • Search for Turn Windows features on or off. You will find a list of features available in Windows
  • Scroll down till you find the following features:
  1. Virtual Machine Platform
  2. Windows Hypervisor Platform
  3. Windows Subsystem for Linux
  • Check or tick these three features and click OK.
  • Your computer will download and install these features from the web. Make sure you have a good internet connection.
  • Once the features are installed, restart your system.

Step 2: Installing Ubuntu 20.04

We need to install Ubuntu as our Linux distribution using the following steps:

  • Click on search button or search bar on the taskbar, search and open Microsoft store.
  • Search for Ubuntu 20.04 LTS on the store. If you can’t find it, click on this link.
  • Click on the Get button. It will start the download, and install the application on your system.
  • After the installation is completed, open Ubuntu from the start menu.
  • A few initialization will progress and it will ask for setting up of username and password for your Linux machine.
  • After setting up your credentials, you will see something like this:
your_username@desktop_name:~$
  • Type pwd (print working directory)in the command line to check your current location in the file system. Your output should look like:
your_username@desktop_name:~$ pwdOUTPUT:/home/your_username

Step 3: Update and set up WSL 2

  • Open the Windows PowerShell as an administrator.
  • Type the following command to check the WSL version in your system:
PS C:\WINDOWS\system32> wsl -l -v
  • If there is no distribution available, you may find the following output:
PS C:\WINDOWS\system32> wsl -l -vOUTPUT:
Windows Subsystem for Linux has no installed distributions.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore
PS C:\WINDOWS\system32>
  • Alternatively, you may find the WSL version displayed as the output.
  • If the VERSION is displayed as 1, you may get the following output:
PS C:\WINDOWS\system32> wsl -l -vOUTPUT:
NAME STATE VERSION
* Ubuntu-20.04 Running 1
PS C:\WINDOWS\system32>
  • In such a case, you need to download an upgrade developed by Microsoft.
  • Install the downloaded package. It may ask for administrator access, click Yes to approve the install. Your WSL version will be upgraded.
  • Now, we need to change the default version of WSL from version 1 to version 2 using the following command:
PS C:\WINDOWS\system32> wsl --set-default-version 2
  • It is recommended to restart the system so that WSL version is updated properly.
  • After restarting your system, open PowerShell as administrator and check the WSL version again using “wsl -l -v”.
  • If the version is still displayed as version 1, you need to execute the following command in the PowerShell to upgrade to WSL version 2:
PS C:\WINDOWS\system32> wsl --set-version Ubuntu-20.04 2OUTPUT:
Conversion in progress, this may take a few minutes...
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
Conversion complete.
  • You can again verify the version using “wsl -l -v” command.

Step 4: Update and Upgrade Ubuntu version

After the WSL version has been updated, it is time to update Ubuntu’s packages and tools.

  • We can update our Ubuntu packages from all repositories and PPA’s (Personal Package Archives) using the following command:
your_username@desktop_name:/$ sudo apt-get update
[sudo] password for your_username:
OUTPUT:A list of packages and PPAs that need an update will be fetched
Reading package lists... Done
  • Now we will upgrade to the newer version of the tools and packages installed on the system using the following command:
your_username@desktop_name:/$ sudo apt-get upgrade
[sudo] password for your_username:
  • You will be asked to give permissions to download, press y followed by an Enter to give the permissions.
  • The installation will begin and you will be upgraded with the latest packages and tools in Ubuntu.

Step 5: Check for mounted drives and tools

Now that Ubuntu has been successfully upgraded, we can see the drives, files, and folders shared between Ubuntu and Windows.

  • You can write the following command to check the mounted drives available using the Ubuntu terminal:
your_username@desktop_name:~$ ls /mnt/OUTPUT:
c d e f g
  • Let’s say we want to enter the “c” drive, we can simply use the “cd” command:
your_username@desktop_name:~$ cd /mnt/cOUTPUT:your_username@desktop_name:/mnt/c$
  • You can also try running python3 on the terminal
hiren@DESKTOP-MKBJJID:/mnt/c$ python3OUTPUT:
Python 3.8.5 (default, May 27 2021, 13:30:53)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Congratulations! You have successfully installed WSL on Windows 10")
OUTPUT:
Congratulations! You have successfully installed WSL on Windows 10
>>>

If all of the above steps have been successfully executed so far, congratulations! You have successfully set up WSL 2 on your Windows 10.

What’s next?

One of India’s leading institutions providing world-class Data Science & AI programs for working professionals with a mission to groom Data leaders of tomorrow!