Install WSL2 on Windows x64 via Pure Command Line (Including Domestic Network Workaround)
This step‑by‑step guide shows how to enable WSL and the virtual machine platform, install the WSL2 kernel (with a fallback download for unstable domestic connections), set WSL2 as the default, install Ubuntu, configure apt sources and timezone, and troubleshoot common errors using administrator PowerShell on Windows 10/11 x64.
Prerequisites
Windows 10 version 1903+ (internal build 18362+) or Windows 11 on x64 architecture, and administrator rights for all PowerShell commands.
1. Enable System Features
# Enable WSL subsystem
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
# Enable Virtual Machine Platform
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestartAfter the two commands complete, restart the computer before proceeding.
2. Install the WSL2 Kernel Update Package
Primary method (when the network works)
wsl --updateIf the connection to Microsoft servers times out, use the fallback method.
Fallback method (recommended for domestic users)
Manually download the kernel MSI and install it silently:
# Download x64 kernel update package
$url = "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi"
$output = "$env:TEMP\wsl_update_x64.msi"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri $url -OutFile $output -UseBasicParsing
# Silent install without user interaction
Start-Process msiexec.exe -ArgumentList "/i \"$output\" /qn /norestart" -Wait
# Clean up temporary file
Remove-Item $output -ForceIf the URL is still inaccessible, download the MSI via a browser and run:
Start-Process msiexec.exe -ArgumentList "/i C:\Temp\wsl_update_x64.msi /qn /norestart" -Wait3. Set Default Version and Install Ubuntu
# Set WSL2 as the default version
wsl --set-default-version 2
# Install Ubuntu (latest LTS by default)
wsl --install -d UbuntuAfter installation, you will be prompted to create a Linux username and password.
Verify the installation:
# VERSION column showing 2 indicates success
wsl -l -v4. Basic Configuration
Inside the Ubuntu terminal:
Replace apt sources with domestic mirrors
# Backup original sources list
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
# Replace with Aliyun mirrors for Ubuntu 22.04 (Jammy)
sudo bash -c 'cat > /etc/apt/sources.list << EOF
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
EOF'
# Update package index
sudo apt update💡 If your Ubuntu version is not 22.04, replace jammy with the appropriate codename (e.g., focal for 20.04, noble for 24.04). Check the version with lsb_release -c .
Set timezone
sudo timedatectl set-timezone Asia/ShanghaiVerify with date; the output should show Beijing time.
Common Issues
❌ Kernel package download timeout : Use the fallback manual download method described in step 2.
❌ Error code 0x80070422 : The LxssManager service is not running. Start it with:
# Run in administrator PowerShell
Start-Service LxssManager
Set-Service -Name LxssManager -StartupType Automatic❌ "WSL 2 needs to update its kernel component" : The kernel package was not installed successfully; repeat step 2.
❌ Network error when running wsl --install : WSL2 needs to download a Linux distribution. If the network is restricted, install Ubuntu offline from the Microsoft Store or complete the first three steps before handling the distribution installation separately.
Related Links
Microsoft official documentation:
WSL installation guide: https://learn.microsoft.com/zh-cn/windows/wsl/install
WSL2 kernel manual download: https://learn.microsoft.com/zh-cn/windows/wsl/install-manualDomestic mirror sources:
Aliyun Ubuntu mirror: https://mirrors.aliyun.com/ubuntu/
USTC Ubuntu mirror: https://mirrors.ustc.edu.cn/ubuntu/Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Tech Ocean
Focused on AI programming, sharing ready-to-use development efficiency solutions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
