How to Install WSL2 on Windows 11 for Beginners

In the world of software development, the ability to seamlessly work across different environments is a considerable advantage. The Windows Subsystem for Linux (WSL) is a fantastic tool that allows developers on Windows to run a Linux environment directly on their machine without the need for a dual boot setup or a virtual machine. This guide will take you step-by-step through setting up WSL2 on Windows 11 for beginners, ensuring you can take full advantage of the power and flexibility that a Linux interface offers while still being able to easily access and use your Windows tools.

Understanding WSL and WSL2

First, it’s important to understand what WSL and WSL2 are and how they differ:


  • WSL (Windows Subsystem for Linux)

    : This initial version of WSL allowed users to run a Linux environment on Windows. It provided a compatibility layer and allowed users to run Linux command-line tools.


  • WSL2

    : This is an enhanced version of WSL. It introduces a full Linux kernel running in a lightweight virtual machine, offering better performance, increased compatibility with Linux applications, and support for additional features like Docker.


WSL (Windows Subsystem for Linux)

: This initial version of WSL allowed users to run a Linux environment on Windows. It provided a compatibility layer and allowed users to run Linux command-line tools.


WSL2

: This is an enhanced version of WSL. It introduces a full Linux kernel running in a lightweight virtual machine, offering better performance, increased compatibility with Linux applications, and support for additional features like Docker.

Prerequisites

Before we dive into the installation, ensure you meet the following prerequisites:

Step 1: Enable WSL

The first step in installing WSL2 is to enable it on your Windows 11 machine. This can be done through either the Command Prompt or Windows Features in settings. Let’s go through both methods.

Method 1: Using PowerShell

Open the Start Menu and search for “PowerShell”.

Right-click on Windows PowerShell and select “Run as administrator”.

Once PowerShell is open, type the following command and press Enter:

The above command will enable the WSL feature and install the latest version of WSL. You might be prompted to restart your computer to complete the installation.

Method 2: Using Windows Features

If you prefer a GUI method:

  • Windows Subsystem for Linux
  • Virtual Machine Platform (Important for WSL2)

Step 2: Set WSL2 as Your Default Version

After enabling WSL, the next step is to ensure that WSL2 is set as the default version. This is crucial, especially if you plan to install specific Linux distributions that may run better under WSL2.

Enter the command:

This command sets WSL2 as your default version for any Linux distribution you install in the future.

Step 3: Install a Linux Distribution

With WSL2 enabled and set as the default, you can now install a Linux distribution of your choice. Thankfully, Windows 11 makes this process quite straightforward.

Open the Microsoft Store by searching “Microsoft Store” in the Start Menu.

In the Microsoft Store, type “Linux” into the search bar. This will display a variety of Linux distributions, such as:

  • Ubuntu
  • Debian
  • Kali Linux
  • OpenSUSE

For beginners,

Ubuntu

is a great choice due to its user-friendly interface and strong community support. Click on Ubuntu (or your preferred distribution) and then click “Install”.

Once the installation is complete, you can launch the distribution directly from the Microsoft Store or find it in the Start Menu.

Step 4: Set Up Your Linux Distribution

After launching your chosen Linux distribution for the first time, you’ll be asked to configure it. Here’s what to expect:

Once this process is completed, you will have access to a fully functional Linux terminal.

Step 5: Update the Linux Package Manager

Before you begin using your Linux system extensively, it’s good practice to update the package manager to ensure that you have the latest packages and security updates.

In your Linux terminal, enter the following commands:

The

sudo apt update

command refreshes the package list.

The

sudo apt upgrade -y

command upgrades all the installed packages to their latest versions.

Step 6: Configuring WSL

While you can start using WSL2 immediately, there are a few configurations that can enhance your experience:

Accessing Windows Files

One of the great benefits of WSL is that you can easily access your Windows files from the Linux shell. Your Windows drives will be mounted under

/mnt

, meaning you can access your C: drive via

/mnt/c

.

Setting Up Your Development Environment

If you plan to use WSL2 for software development, consider installing essential tools and languages. Some common setups include:


  • Installing Git

    :

    sudo apt install git

  • Installing Node.js

    :

    Follow these steps to install Node.js:

    curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
    sudo apt install -y nodejs

  • Installing Python

    :

    sudo apt install python3 python3-pip

  • Installing Docker

    : For containerization, Docker can be installed on WSL2 and is often configured using Docker Desktop.


Installing Git

:


Installing Node.js

:

Follow these steps to install Node.js:


Installing Python

:


Installing Docker

: For containerization, Docker can be installed on WSL2 and is often configured using Docker Desktop.

Customizing Your Terminal

For a better terminal experience, consider customizing your terminal settings or using a terminal emulator like Windows Terminal:


Install Windows Terminal

: Search for “Windows Terminal” in the Microsoft Store and install it.


Customization

: You can customize your profile in Windows Terminal to differentiate between your PowerShell, Command Prompt, and WSL sessions.

Step 7: Common Commands and Tips

Familiarizing yourself with some common commands and tips can significantly enhance your usage of WSL2:


  • Updating WSL

    : You can ensure that WSL is updated by running:

    wsl --update

  • Listing Installed Distributions

    :

    wsl --list --verbose

  • Launching Specific Distribution

    : To launch a specific distribution from PowerShell, you can use:

    wsl -d Ubuntu

  • Stopping WSL

    : If you need to shut down all running WSL instances, simply use:

    wsl --shutdown


Updating WSL

: You can ensure that WSL is updated by running:


Listing Installed Distributions

:


Launching Specific Distribution

: To launch a specific distribution from PowerShell, you can use:


Stopping WSL

: If you need to shut down all running WSL instances, simply use:

Step 8: Troubleshooting Common Issues

While the installation process is straightforward, you may encounter issues that require troubleshooting. Here are some common solutions:


Cannot Run Commands

: If you are unable to run certain commands, ensure that your Linux distribution is properly installed and up to date.


Memory and Performance Issues

: WSL2 uses a lightweight virtual machine which may require tweaking resource settings. You can control memory allocation and processor usage by creating a

.wslconfig

file in your user directory (C:Users.wslconfig) and adding the following configuration:


Accessing Windows Files

: If you experience issues accessing Windows files, ensure that your drives are properly mounted. You can also check your WSL version with:

Conclusion

Installing WSL2 on Windows 11 is an empowering step for developers, technology enthusiasts, or anyone who wants to explore the Linux ecosystem. With the ability to run Linux natively alongside Windows, you unlock a plethora of tools and utilities that can streamline your workflow and enhance productivity.

By following these steps, you’ve successfully installed WSL2, set up your Linux environment, and begun to customize it for your needs. Remember, the Linux community is vast and welcoming, so don’t hesitate to seek help or further your learning with the plethora of resources available online.

As you familiarize yourself with WSL2, you’ll find that the capabilities it provides can simplify tasks, improve development processes, and open new avenues for exploration and creativity. Happy coding!

Leave a Comment