How do I install WSL?

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