windows 10 wsl 2 code example

Example 1: update to wsl2

#enable wsl 
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
#make sure windows version is >=2004
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
#restart
wsl --set-default-version 2
#if kernal error https://docs.microsoft.com/en-us/windows/wsl/wsl2-kernel

Example 2: windows features windows subsystem for linux not

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Example 3: wsl2 windows 10

//Enable WSL 2 on windows 10 - Run these from an admin powershell
//Enable Microsoft Hyper V first
DISM /Online /Enable-Feature /All /FeatureName:Microsoft-Hyper-V
bcdedit /set hypervisorlaunchtype auto
wsl.exe --set-version Ubuntu 2

"The Hyper-V feature is not required, but Virtual Machine Platform (which includes the Hyper-V hypervisor) is required"

Example 4: ubuntu wsl windows 10

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Example 5: enable wsl2

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart