Setting Up WSL 2 in Windows 10
(A Beginners Guide to Setup Windows Subsystem for Linux 2)
Written in collaboration with Hiren Rupchandani
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 natively (such as Ubuntu) on Windows. It offers 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 a certain amount of resources such as hard-drive space for a file system, some CPU cores, and 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 alternatively, it 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 that many tools, languages, and libraries are developed for the Linux environments where they can have seamless communication with each other. Their Windows-ported versions are either unavailable or inefficient, which enforces users to migrate between different operating systems. So, WSL was developed to address such issues and lets users use Bash and Linux command-line tools on Windows itself.
So, now that you have obtained a high-level overview of WSL and its need, let me guide you to its setup on Windows 10.
Prerequisites for WSL 2
The latest version of WSL is version 2. We will be installing Ubuntu as our Linux distribution for WSL 2. 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:
Setting Up Ubuntu as WSL
Now that our system is compatible to install Ubuntu as WSL, let’s proceed…
Step 1: Enable features on Windows 10
- Click on the search button or search bar on the taskbar.
- 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:
- Virtual Machine Platform
- Windows Hypervisor Platform
- 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 get downloaded and 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 the search button or search bar on the taskbar, and search and open the 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.
- Once the installation gets completed, open Ubuntu from the start menu.
- A few initializations will progress, and it will ask for the 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 this:
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 you see the VERSION showing as 1, you will get the output as follows:
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 and install it.
- Approve the administrator access for installation by clicking Yes, if required.
- Your WSL version will get upgraded, and all that is left will be to change the default version of WSL from version 1 to version 2, which you can do using the following command:
PS C:\WINDOWS\system32> wsl --set-default-version 2
- Next, restart the system for WSL to be in sync with the system.
- After restarting your system, open PowerShell as administrator and verify the WSL version using “wsl -l -v”.
- If the output still shows 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 again using the “wsl -l -v” command.
Step 4: Update and Upgrade the Ubuntu version
After the WSL version gets 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:
- Your system will ask for permission to download the latest tools and packages.
- Press y followed by an Enter to grant the permissions.
- The installation will begin, and your Ubuntu will get upgraded with the latest packages and tools.
Step 5: Check for mounted drives and tools
Upon successful upgradation of Ubuntu, you 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 you want to enter the “c” drive, then you 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
mukesh@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 the above steps get successfully executed, congratulations! You have successfully set up WSL 2 on your Windows 10.
Final Thoughts and Closing Comments
There are some vital points many people fail to understand while they pursue their Data Science or AI journey. If you are one of them and looking for a way to counterbalance these cons, check out the certification programs provided by INSAID on their website. If you liked this story, I recommend you to go with the Global Certificate in Data Science because this one will cover your foundations plus machine learning algorithms (basic to advance).
& That’s it. I hope you liked the explanation of Setting Up WSL 2 in Windows 10 and learned something valuable. If you have anything to share with me, let me know in the comment section. I would love to know your thoughts.
Follow me for more forthcoming articles based on Python, R, Data Science, Machine Learning, and Artificial Intelligence.
If you find this read helpful, then hit the Clap👏. Your encouragement will catalyze inspiration to keep me going and develop more valuable content.