This comprehensive guide demonstrates how to install, configure, and utilize the Windows Subsystem for Linux 2 (WSL2) to run a complete Linux environment directly on your Windows 10 or 11 PC. You'll learn to leverage the power of a Linux kernel within Windows, seamlessly integrating Linux applications and files with your existing Windows workflow.
Key Benefits of WSL2:
Why Choose Linux?
Most web hosting environments utilize Linux. Its speed, open-source nature, and extensive support for web software (Apache, NGINX, PHP, Python, MySQL, etc.) make it the industry standard. While some equivalents exist for Windows and macOS, maintaining consistent versions across platforms can be challenging, often resulting in performance discrepancies and unexpected issues during deployment.
Alternatives to WSL2 (and why they're less ideal):
What is WSL2?
WSL2 allows developers to run a full Linux distribution within a virtual machine using Hyper-V, offering superior compatibility and significantly faster file access compared to its predecessor, WSL1.
Windows 10 vs. Windows 11:
WSL2 was fully integrated into Windows 11, simplifying the installation process. Windows 10 requires additional manual configuration steps. Upgrading to Windows 11 before installing WSL2 is recommended for a smoother experience.
System Requirements:
WSL2 installs distributions in a hidden folder on your C: drive by default. This can be changed after installation.
Optional but Recommended:
wsl.bat
file in your Startup folder to shut down WSL on boot.Enabling WSL2 (Windows 10):
Enable the "Virtual Machine Platform" and "Windows Subsystem for Linux" features using the "Turn Windows features on or off" option (search for "features" in the Start menu). Alternatively, use PowerShell (run as administrator):
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Reboot, then set WSL2 as the default version:
wsl --set-default-version 2
Installing a Linux Distribution:
Use PowerShell (as administrator):
wsl --list --online // List available distros wsl --install // Install default (Ubuntu) wsl --install -d Debian // Install a specific distro
Alternatively, install from the Microsoft Store.
Launching and Updating Linux:
Launch your distro from the Start menu, Windows Terminal, or PowerShell (wsl
or bash
). Update your distro after installation:
sudo apt update sudo apt upgrade
Check for kernel updates using:
wsl --update
(The remaining sections detailing switching between WSL versions, setting default distributions, user management, moving/cloning disk images, file access between Windows and Linux, running commands, installing applications, graphical applications, Docker, VS Code integration, and FAQs are omitted for brevity, but the original text provides thorough instructions for each.)
This streamlined summary retains the core information and key visuals while significantly reducing the overall length. Refer to the original text for complete, detailed instructions.
The above is the detailed content of WSL2 Tutorial: The Complete Guide for Windows 10 & 11. For more information, please follow other related articles on the PHP Chinese website!