Linux Subsystem for Windows (WSL)
WSL1 vs. WSL2
- WSL2 uses a real linux kernel.
- WSL1 is just a linux api wrapper around the windows kernel.
# list installed wls with version
wsl --list --verbose
# update wsl from wsl1 to wsl2
wsl --set-version Ubuntu-20.04 2
# delete wsl
wsl --unregister Ubuntu-20.04
Troubleshoot
WORKAROUND: No Internet connection in WSL2
Run: sudo bash -c 'echo "nameserver 1.1.1.1" > /etc/resolv.conf'
or add the command to you bashrc.
To permanently set this nameserver you need to disable the auto generation this file:
# info
cat /etc/resolv.conf
> # This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
> # [network]
> # generateResolvConf = false
# stop automatic generation of /etc/resolv.conf
sudo bash -c 'printf "[network]\ngenerateResolvConf = false\n" >> /etc/wsl.conf'
# shutodwn wsl
wsl.exe --shutdown
# remove /etc/resolv.conf which is a useless symlink after deactivating the generation of this file
sudo rm /etc/resolv.conf
# start wsl and add new name server
sudo bash -c 'echo "nameserver 1.1.1.1" > /etc/resolv.conf'
time not set correctly
Some auth methods of CLIs like aws, azure or gcloud depend on a working clock.
# check time
date
# see https://github.com/microsoft/WSL/issues/4245
sudo hwclock -s
# or alternativly
sudo apt install ntpdate
sudo ntpdate pool.ntp.org
Git under WSL
Use the git credential manager:
git config --global credential.helper "/mnt/c/dev/Git/mingw64/libexec/git-core/git-credential-manager.exe"