How to Install and Use Windows Subsystem for Linux 2 (WSL2) on Windows 11

This guide provides detailed instructions on how to install and use the Windows Subsystem for Linux 2 (WSL2) in Windows 11, enabling you to run a full Linux environment directly on your Windows PC.

Overview

WSL2 is an enhancement over the original Windows Subsystem for Linux, featuring a full Linux kernel, improved system compatibility, and performance upgrades. It allows developers to run a GNU/Linux environment including most command-line tools, utilities, and applications directly on Windows, unmodified, without the overhead of a traditional virtual machine or dualboot setup.

Features

  • Full Linux Kernel: WSL2 uses a real Linux kernel that enhances performance and app compatibility over WSL1.
  • Integrated Windows and Linux Filesystems: Access your Windows files from Linux and vice versa.
  • Native Docker Container Support: Run Docker natively on Windows 11 with WSL2, greatly improving Docker performance.

Getting Started

Prerequisites

  • A PC running Windows 11 updated to the latest version.
  • Virtual Machine Platform enabled in Windows Features.

Installation

Enable the Windows Subsystem for Linux and Virtual Machine Platform

  1. Open PowerShell as Administrator:
  • Right-click on the Start button and select “Windows PowerShell (Admin)”.
  1. Install WSL:
  • Enter the command: wsl --install and press Enter. This command will install WSL2, set it as the default version, and install a Linux distribution (Ubuntu by default).

Set WSL 2 as Your Default Version

  1. Open PowerShell as Administrator:
  • Run the command: wsl --set-default-version 2.

Installing a Linux Distribution

  1. Open Microsoft Store:
  • Search for your preferred Linux distribution (e.g., Ubuntu, Debian, Fedora).
  1. Install Linux Distribution:
  • Click “Get” and then “Install” on your chosen Linux distribution.

Running Your Linux Distribution

  • Launch the Linux Distribution:
  • Click on the Start menu, find your Linux distribution, and click to run it.
  • Set up your new user account and password within the Linux console.

Best Practices

  • Keep Your WSL Up to Date:
  • Regularly update your Linux distribution and packages using your distro’s package manager (e.g., sudo apt update && sudo apt upgrade for Debian/Ubuntu).
  • Integrate WSL with Windows Development Tools:
  • Utilize tools like Visual Studio Code with the Remote – WSL extension to develop within the Linux environment from Windows.

Troubleshooting

  • WSL Not Working or Errors Installing:
  • Ensure that virtualization is enabled in your BIOS/UEFI settings.
  • Check for Windows updates and apply any pending ones.
  • Performance Issues:
  • Allocate additional resources if necessary or check for specific WSL2 optimizations.

Conclusion

WSL2 offers a powerful environment for development, particularly for cross-platform applications, web development, and more. By integrating Linux seamlessly with your Windows workflow, it provides the best of both worlds.

For more detailed guidance or support, visit the Windows Subsystem for Linux documentation.

Similar Posts