You can find the source of truth for managing WSL distributions over at Manage and configure Windows Subsystem for Linux.
Today while attempting to install some Alpine packages in my WSL distribution the distro started being naughty and did not want
sudo ping google.com or install manually downloaded Alpine packages.
Over at https://github.com/gliderlabs/docker-alpine/issues/348 someone recommended messing around with perms in
/usr and well, here we are lol. I borked my
sudo permissions, and no longer being able to do anything in my Alpine distribution, it’s time to start from scratch. That’s what these WSL distributions are there for.
How to uninstall
The command spec is
wsl --unregister <DistributionName> . In my case it was:
wsl --unregister Alpine
From a Windows command line
cmd.exe or PowerShell instance:
You don’t need administrative permissions or an elevated shell to run these, which is great!
After that you can simply go to the Windows Store on your machine, and re-download the distribution:
After the distribution is downloaded, you can click on the Launch button, and it will open a shell to the distribution:
When you open this new shell, the WSL management engine will install the distribution proper, and ask you for a new username. In my case I choose
wsl for my username:
After a fresh Alpine WSL installation, you won’t have
sudo out of the box. To open a
root shell into Alpine WSL, from
cmd.exe or PowerShell:
wsl --distribution Alpine --user root
Then setup a password for the
root user, and install the
sudo apk package:
# Set password for root
passwd# Install sudo package
apk add sudo
After that edit the
/etc/sudoers file with
visudo /etc/sudoers , and modify the
Add the group
Add your current user to the
usermod -aG sudo wsl
Verify contents of the
/etc/group file, to make sure your default user is now included in the
Add password to the default user, in my case
And we’re on our merry way to the rest of the day!