Keeping your WSL Linux instances up to date automatically within Windows 10
Hayden Barnes from Canonical, the folks that work on Ubuntu (lovely blog, check out it) had a great tweet where he recommended using the Windows Task Scheduler (think of it as a graphical cron job manager) to keep your WSL Linux instances up to date.
There's a few things to unpack here to get into the details.
First, if you run wsl --list -v you'll see all the WSL Linux Instances on your machine.
> wsl --list -v
NAME STATE VERSION
* Ubuntu-18.04 Running 2
kali-linux Stopped 1
Alpine Stopped 1
Ubuntu-20.04 Stopped 2
WLinux Running 2
docker-desktop-data Stopped 2
docker-desktop Stopped 2
You can I see I have a few. I spend most of my time in the Ubuntu instances, but I also occasionally drop into the kali-linux and WLinux instances. If I'm using LTS (long term support) distros then there's minimal risk (my opinion) in "apt get update" and "apt get upgrade"-ing them every week or so. I could even do it unattended.
I could set up a Task Scheduler and make an "on login" task or a weekly task that calls wsl.exe and passes in -d for distro, along with the name of the distro, run as root with -u and -e for the command. For example:
wsl -d "Wlinux" -u root -e apt update
wsl -d "Wlinux" -u root -e apt upgrade -y
Since I have several WSL instances, I could also make a "updateall.cmd" or .bat or .ps1 script and run them occasionally to keep them all updated on my own. Just change the -d and include the name of each distro. One could imagine a group policy as well for large enterprises to do the same thing for developers using a custom or managed WSL instance.
You would not want to update or mess with the docker- managed WSL instances above as they exist only to run your Docker Desktop-managed containers. Leave that to Docker to manage.
It's a whole new world out there, and I'm loving how I can move easily between multiple Linuxes on Windows 10. Check out my YouTube on WSL2 and please subscribe over there.
Sponsor: Never miss a beat with Seq. Live application logs and health checks. Download the Windows installer or pull the Docker image now.