Curious Minds

Clear answers to science and history questions

Use WSL: Your Guide to Windows Subsystem for Linux

· 5 min read · Science

Windows Subsystem for Linux (WSL) allows you to run a Linux environment—including most command-line tools, utilities, and applications—directly on Windows, without needing a virtual machine or dual booting. It's a game-changer for developers who want to leverage Linux tools within their Windows workflow, and it can be useful for anyone who needs access to Linux software. This guide provides a comprehensive walkthrough of setting up and using WSL.

What You'll Need

  • Windows 10 (version 2004 or higher) or Windows 11: WSL 1 was available on older versions, but WSL 2 offers significantly improved performance and is recommended. Check your Windows version by typing "winver" in the Windows search bar.
  • Administrative privileges: You'll need administrator rights on your Windows machine to install WSL and its components.
  • Sufficient disk space: Linux distributions can take up several gigabytes of space. Ensure you have enough free space on your system drive.
  • Internet connection: Required for downloading the Linux distribution and updates.

Step-by-Step

  1. Enable the "Windows Subsystem for Linux" feature: Open PowerShell as an administrator (right-click the Start button and select "Windows PowerShell (Admin)"). Type the following command and press Enter:
    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
    You'll be prompted to restart your computer.
  2. Enable the "Virtual Machine Platform" feature (for WSL 2): Again, open PowerShell as an administrator and run:
    Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
    Restart your computer when prompted.
  3. Download and Install WSL 2 Kernel Update Package: This is crucial for WSL 2 performance. Download the latest package from the Microsoft website (search for "WSL2 Kernel Update Package"). Run the installer and follow the on-screen instructions.
  4. Choose and Install a Linux Distribution: Open the Microsoft Store. Search for your desired Linux distribution (e.g., Ubuntu, Debian, Kali Linux, Fedora). Click "Get" and then "Install."
  5. Launch the Linux Distribution: Once installed, click "Launch" from the Microsoft Store page, or search for the distribution's name in the Windows search bar. The first time you launch it, it will take a few minutes to complete the installation.
  6. Create a User Account: After the initial installation, you'll be prompted to create a username and password for your Linux environment. This is separate from your Windows account.
  7. Update and Upgrade Packages: Open your Linux terminal. It's always a good idea to update the package lists and upgrade existing packages:
    sudo apt update && sudo apt upgrade
    (This command is specific to Debian/Ubuntu-based distributions. Other distributions may use different package managers and commands - e.g., `sudo dnf update` for Fedora).
  8. Access Windows Files from WSL: Your Windows drives are automatically mounted within the WSL file system. You can access them under `/mnt/`. For example, your C: drive is located at `/mnt/c/`.
  9. Access WSL Files from Windows: Accessing WSL files from Windows can be a bit trickier. The easiest way is to type `\\wsl$` in File Explorer's address bar. This will show you a list of your installed Linux distributions. You can then navigate to their file systems. Be aware that performance can be slower when accessing WSL files from Windows.

Common Mistakes

  • Not enabling the "Virtual Machine Platform" feature: This is essential for WSL 2, which significantly improves performance.
  • Using an outdated version of Windows: WSL 2 requires Windows 10 version 2004 or later, or Windows 11.
  • Forgetting to install the WSL 2 Kernel Update Package: This is a frequent cause of errors and poor performance.
  • Trying to access WSL files directly from the Windows root directory: Always use `/mnt/` within WSL or `\\wsl$` within Windows.
  • Incorrectly using `sudo`: `sudo` is used to run commands with administrator privileges within the Linux environment. Use it only when necessary.
  • Confusing Windows paths with Linux paths: Windows uses backslashes (`\`) as path separators, while Linux uses forward slashes (`/`).

Tips

  • Use a terminal emulator: While the default WSL terminal is functional, consider using a more advanced terminal emulator like Windows Terminal (available from the Microsoft Store) for better customization and features.
  • Customize your Linux environment: Install your favorite text editors, IDEs, and other tools to tailor your Linux environment to your specific needs.
  • Learn basic Linux commands: Familiarize yourself with common Linux commands like `ls`, `cd`, `mkdir`, `rm`, `cp`, `mv`, and `grep`.
  • Use a version control system: Integrate WSL with Git for version control of your projects.
  • Explore WSL distributions: Experiment with different Linux distributions to find the one that best suits your workflow.
  • Configure WSL 2 for improved performance: By default, WSL 2 stores the virtual hard disk in a dynamically expanding VHDX file. For better performance, you can move the VHDX file to a faster storage device (e.g., an SSD).

Troubleshooting

  • WSL not launching: Ensure that the "Windows Subsystem for Linux" and "Virtual Machine Platform" features are enabled. Verify that you have the latest WSL 2 Kernel Update Package installed.
  • Network connectivity issues: Check your Windows firewall settings to ensure that WSL is not being blocked.
  • Slow performance: Make sure you are using WSL 2. Move the VHDX file to a faster storage device. Close unnecessary applications running in Windows.
  • Error messages related to virtualization: Ensure that virtualization is enabled in your computer's BIOS/UEFI settings.
  • File permission errors: Use `chmod` to change file permissions within the Linux environment.
  • WSL distribution not showing up in `\\wsl$`: Restart your computer. Ensure the distribution is properly installed and running.

Frequently Asked Questions

What is the difference between WSL 1 and WSL 2?

WSL 2 utilizes a lightweight virtual machine to run the Linux kernel, providing significantly improved file system performance and full system call compatibility compared to WSL 1. WSL 1 translates Linux system calls to Windows NT APIs.

Can I run graphical applications in WSL?

Yes, with WSL 2, you can run graphical Linux applications. You'll need to install an X server on Windows (e.g., VcXsrv or X410) and configure your Linux environment to use it.

How do I update WSL?

You can update WSL using the `wsl --update` command in PowerShell. It's recommended to update regularly to benefit from the latest features and bug fixes.

Can I have multiple Linux distributions installed?

Yes, you can install and run multiple Linux distributions simultaneously. Each distribution will have its own separate terminal and file system.

How do I uninstall a WSL distribution?

Open PowerShell as an administrator and use the command `wsl --unregister `, replacing `` with the name of the distribution you want to remove (e.g., `wsl --unregister Ubuntu`).
In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions