Skip to main content

Command Palette

Search for a command to run...

How do I install WSL?

Updated
4 min read
J

I am Jyotiprakash, a deeply driven computer systems engineer, software developer, teacher, and philosopher. With a decade of professional experience, I have contributed to various cutting-edge software products in network security, mobile apps, and healthcare software at renowned companies like Oracle, Yahoo, and Epic. My academic journey has taken me to prestigious institutions such as the University of Wisconsin-Madison and BITS Pilani in India, where I consistently ranked among the top of my class.

At my core, I am a computer enthusiast with a profound interest in understanding the intricacies of computer programming. My skills are not limited to application programming in Java; I have also delved deeply into computer hardware, learning about various architectures, low-level assembly programming, Linux kernel implementation, and writing device drivers. The contributions of Linus Torvalds, Ken Thompson, and Dennis Ritchie—who revolutionized the computer industry—inspire me. I believe that real contributions to computer science are made by mastering all levels of abstraction and understanding systems inside out.

In addition to my professional pursuits, I am passionate about teaching and sharing knowledge. I have spent two years as a teaching assistant at UW Madison, where I taught complex concepts in operating systems, computer graphics, and data structures to both graduate and undergraduate students. Currently, I am an assistant professor at KIIT, Bhubaneswar, where I continue to teach computer science to undergraduate and graduate students. I am also working on writing a few free books on systems programming, as I believe in freely sharing knowledge to empower others.

For the Windows group of operating systems, the Windows Subsystem for Linux (WSL) serves as a compatibility layer that allows Linux binary executables to execute natively. Said another way, it spares customers the hassles of a dual-boot or traditional virtual machine by enabling them to install and operate a GNU/Linux environment straight on Windows.

With the help of WSL, users can select and run a GNU/Linux distribution from the Microsoft Store thanks to a kernel interface that was created by Microsoft and is compatible with Linux (it does not contain any Linux kernel code). This implies that you may execute Linux command-line programs, such as tools, utilities, and programming languages that are generally included in a Linux distribution, as well as Bash shell scripts.

WSL comes in two versions:

WSL 1: The first iteration of WSL is a user-mode session manager service that manages the Linux instance and implements a kernel interface that is compatible with Linux. It enables the Linux binaries to execute on Windows by translating Linux system calls to Windows system calls.

WSL 2: A real Linux kernel operates in a lightweight virtual machine environment in this more recent iteration of WSL. In comparison to WSL 1, it offers enhanced system call compatibility, performance gains, and native support for Docker container operations.

Developers who need to use Linux-based tools and apps on Windows computers without requiring a separate Linux workstation or server may find WSL especially helpful. It's also useful for running servers or software that's only reliable or available on Linux platforms, learning Linux or Unix commands, and for educational purposes.

You can use the following comprehensive instructions to install the Windows Subsystem for Linux (WSL):

  1. Open PowerShell as Administrator:

    • Search for PowerShell in your Start menu, right-click on it, and select "Run as administrator".
  2. Enable the WSL Feature:

    • In the PowerShell window, type the following command and press Enter:

        dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
      
  3. Enable Virtual Machine Feature:

    • For WSL 2, you also need to enable the Virtual Machine Platform feature. In the same PowerShell window, type the following command and press Enter:

        dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
      
  4. Download the Linux Kernel Update Package:

  5. Set WSL 2 as the Default Version:

    • Once the Linux kernel update package is installed, open PowerShell as administrator again and run the following command to set WSL 2 as the default version when installing a new Linux distribution:

        wsl --set-default-version 2
      
  6. Install a Linux Distribution:

    • Open the Microsoft Store and search for your preferred Linux distribution (e.g., Ubuntu, Debian, Fedora, etc.).

    • Select the distribution and click "Get" or "Install" to download and install it.

  7. Initialize the Linux Distribution:

    • Once the Linux distribution is installed, launch it from the Start menu by searching by its name. For example, if you installed Ubuntu, search for "Ubuntu" and you should see it.

    • The first time you launch a newly installed Linux distribution, a console window will open, and you'll need to wait for files to decompress and be stored on your machine. Then, you'll need to create a user account and password for your new Linux distribution.

  8. Update and Upgrade (Optional but Recommended):

    • It's a good practice to update and upgrade your Linux distribution's packages. You can do this by running the following commands in your Linux console:

        sudo apt update && sudo apt upgrade
      
  9. Verify Installation:

    • To verify that WSL 2 is installed and running, you can use the following command in PowerShell:

        wsl --list --verbose
      
    • This will list all installed Linux distributions and show which WSL version each is using.

  10. Install dev tools:

    To be able to use gcc (for C development) do this:

    sudo apt update && sudo apt install build-essential
    

More from this blog

Jyotiprakash's Blog

251 posts

I'm Jyotiprakash, a software dev and professor at KIIT, with expertise in system programming.