December 4, 2024

How to Install a Linux Distribution on WSL (Windows Subsystem for Linux)

mr rockstar

How to Install a Linux Distribution on WSL (Windows Subsystem for Linux)
Cheap Dedicated Server

How to Install a Linux Distribution on WSL (Windows Subsystem for Linux): A Step-by-Step Guide

The Windows Subsystem for Linux (WSL) has revolutionized how developers and enthusiasts interact with Linux on Windows. By allowing you to run a full Linux distribution within Windows without the need for a virtual machine or dual-boot setup, WSL provides a powerful and efficient way to explore Linux. This guide walks you through installing a Linux distribution on WSL.


What is WSL?

WSL is a compatibility layer in Windows that allows you to run Linux natively, enabling seamless integration of Linux tools with your Windows environment. With WSL 2, you also get a real Linux kernel for better performance and compatibility.


Prerequisites

  1. Windows Version: You need Windows 10 (version 2004 or later) or Windows 11.
  2. Administrative Rights: Ensure you have administrator privileges on your system.
  3. Internet Connection: Required to download the Linux distribution.

Step 1: Enable WSL

To get started, you need to enable the WSL feature in Windows:

  1. Open PowerShell as Administrator.
  2. Run the following command to enable the required features:
     

    wsl --install

     

    Enable WSL

    This command will:

    • Enable the WSL feature.
    • Install the virtual machine platform.
    • Download and install a default Linux distribution (typically Ubuntu).
  3. Restart your computer when prompted.

Step 2: Choose and Install a Linux Distribution

If you want to install a specific Linux distribution or add another one:

  1. Open the Microsoft Store.
  2. Search for your desired Linux distribution, such as:
    • Ubuntu (various versions)
    • Debian
    • Kali Linux
    • Fedora
    • openSUSE
  3. Click Install to download and set up the distribution.

Alternatively, you can use PowerShell to install a specific distribution. For example:
PowerShell to install a specific distribution

 

wsl --install -d Ubuntu-22.04

 


Step 3: Set Up Your Linux Environment

  1. After installation, launch your Linux distribution either from the Start menu or by typing its name in a terminal.
  2. The first time you launch the distro, it will complete setup and prompt you to:
    • Create a new user.
    • Set a password for the user.
  3. Once completed, you will have access to a Linux terminal.

Step 4: Configure WSL Version

By default, WSL 2 is used. To confirm or change the version for your distribution:

  1. Check the current version of WSL:
    Check the current version of WSL

     

     

    wsl --list --verbose

     

  2. Set a distribution to WSL 2 (if needed):
    Set a distribution to WSL 2

     

     

    wsl --set-version <distro-name> 2

     

    Replace <distro-name> with the name of your distribution.

  3. If you want all future installations to default to WSL 2:
    If you want all future installations to default to WSL 2

     

     

    wsl --set-default-version 2

     


Step 5: Explore Your Linux Distro

Once installed, you can start exploring and using Linux on your Windows machine:

  • Access the Linux file system via /home or /mnt/c for Windows drives.
  • Install packages using the native package manager (e.g., apt, dnf, or zypper).
  • Use Linux tools like vim, git, curl, and ssh.

Tips and Tricks

  1. Access Linux Files from Windows: Navigate to \\\\wsl$\\<distro-name> in File Explorer to access your Linux files.
  2. Run Linux Commands in PowerShell: Use wsl followed by a command:
    Run Linux Commands in PowerShell

     

     

    wsl ls -la

     

  3. Backup Your Linux Distro: Export your distro for backup or transfer:
    Backup Your Linux Distro

     

     

    wsl --export <distro-name> <file-name>.tar

     

  4. Update Your Linux Kernel: Keep the kernel updated with:
    Update Your Linux Kernel

     

     

    wsl --update

     


Common Troubleshooting

  • Error: “WSL is not enabled”: Make sure the WSL feature is enabled in Windows Features.
  • Low Disk Space: Consider resizing the virtual disk used by WSL 2.
  • Networking Issues: Restart the LxssManager service or troubleshoot firewall rules.

Conclusion

Installing and running a Linux distribution on WSL is a straightforward process, providing a great way to enjoy the best of both Windows and Linux environments. Whether you’re a developer, sysadmin, or Linux enthusiast, WSL opens doors to new workflows and tools without leaving the comfort of Windows.

Have you tried using WSL? Share your experiences and favorite Linux distributions below!

Install a Linux Distribution on WSL (F.A.Q)

 

Can I run multiple Linux distributions on WSL?

Yes, you can install and run multiple Linux distributions side by side. Use wsl --list to see installed distributions and launch them independently.

How do I update my Linux distribution on WSL?

Use your distribution’s package manager to update:
For Ubuntu/Debian:

 
sudo apt update && sudo apt upgrade

What is the difference between WSL 1 and WSL 2?

  • WSL 1: Translates Linux calls to Windows kernel calls (faster file I/O with Windows files).
  • WSL 2: Uses a real Linux kernel in a lightweight VM, offering better compatibility and performance.

 

Can I access Windows files from Linux in WSL?

Yes, your Windows drives are mounted under /mnt/. For example, the C drive is accessible at /mnt/c.

 

Popular Blog Posts