How to Enable WSL2 on Windows Machine
A step-by-step beginner’s guide to enabling WSL2 on Windows for Linux development
Windows Subsystem for Linux (WSL2) lets you run Linux environments directly on Windows, making it a powerful tool for developers. This guide walks you through setting up WSL2 step-by-step, explaining each command clearly.
Enable Features
To start, you need to enable key Windows features to support WSL2. These commands require Administrator privileges, so run them in an elevated Command Prompt or PowerShell (right-click and select "Run as Administrator").
Enable Virtual Machine Platform
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
This command enables the Virtual Machine Platform, which WSL2 uses to run Linux in a lightweight virtual machine. The /norestart flag prevents an immediate system reboot, letting you enable other features first.
Enable Windows Subsystem for Linux
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
This enables the core WSL feature, allowing Windows to support Linux distributions. Again, /norestart delays the required system reboot.
Restart the system
After enabling both features, restart your computer to apply the changes. This is critical for WSL2 to work properly.
Verify Installation
Once your system restarts, check if WSL is installed correctly.
wsl --version
This command displays the installed WSL version. If it runs without errors, WSL is set up. You might see details like the WSL version and default distribution (if any).
Update WSL2
To ensure you have the latest WSL2 features and fixes, update it.
wsl --update
This command downloads and installs the latest WSL updates from Microsoft. It’s a good practice to run this periodically to keep WSL2 current.
Set Default WSL Version
Finally, configure WSL2 as the default version for new Linux distributions.
wsl --set-default-version 2
This sets WSL2 as the default for any Linux distributions you install later. WSL2 offers better performance and compatibility compared to WSL1, making it ideal for most development tasks.
By following these steps, you’ve enabled and configured WSL2 on your Windows machine. You’re now ready to install a Linux distribution (like Ubuntu) from the Microsoft Store and start exploring Linux tools in a DevOps environment!