Installing WSL 2
Tested on Windows 10.
Pre-requirements #
- Windows 10 May 2020 (2004) // or older Windows 10 May 2019 (1903) / or Windows 10 November 2019 (1909)
- A computer with Hyper-V Virtualization support
Steps Overview #
- Enable WSL 2
- Enable ‘Virtual Machine Platform’
- Set WSL 2 as default
- Install a Linux distro
- Download the lateest kernel to update [ref]
Powershell CML for Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11 #
wsl --install
Powershell CML for Win before Win-2004 (Build 19041) #
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart # Enable WSL
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart # Enable ‘Virtual Machine Platform’
# Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart # for even older win10
wsl --list --verbose
# wsl --set-version <ubuntu-dist-NAME> 2 # for even older win10 # convert current if installed
wsl --set-default-version 2 # use WSL2 for future installations
Then install from Microsoft Store. Do NOT use VPN! Do NOT install the preview version, instead, install the version that matches “ubuntu-dist-NAME” given by wsl --list --verbose
.
Other versions for advanced users: wsl --list --online; wsl --install -d <dist-NAME>
.
ref: OMG Ubuntu.co.uk
Install GUI #
NOT for advanced users!
sudo apt update && sudo apt install x11-apps
Debug #
cannot resovle domains #
Solution: disable auto-generation of resolv.conf by editing /etc/wsl.conf
inside the WSL sys:
[network]
generateResolvConf = false
then shutdown WSL to restart WSL so this config could take effect by wsl.exe --shutdown
.
Later, the /etc/resolv.conf
could be modified as needed.
no network #
::=============================================================================
::FIX WSL2 NETWORKING IN WINDOWS 10
::=============================================================================
cmd as admin:
wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
:: and restart windows
If does not work, do the following inside WSL before the above commands in Windows.
# Fix network issues
# Delete auto-generated files
[root@PC-NAME user]# rm /etc/resolv.conf || true
[root@PC-NAME user]# rm /etc/wsl.conf || true
# Enable changing /etc/resolv.conf
# Enable extended attributes on Windows drives
[root@PC-NAME user]# cat <<EOF > /etc/wsl.conf
[network]
generateResolvConf = false
[automount]
enabled = true
options = "metadata"
mountFsTab = false
EOF
# Use cn & google nameservers for DNS resolution
[root@PC-NAME user]# cat <<EOF > /etc/resolv.conf
nameserver 114.114.114.114
nameserver 8.8.4.4
EOF