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.
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter
e.g. <i>wsl -d "Wlinux" -u root -e apt update && apt upgrade -y</i>
https://github.com/RobCannon/my-centos
<pre>
PS> wsl --list -q |? {$_ -ne "`0"} |% {wsl -d "$_" -u root -e 'apt update ; apt upgrade -y'}
There is no distribution with the supplied name.
PS> wsl --list -q |? {$_ -ne "`0"} |% {"wsl -d $_ -u root -e 'apt update ; apt upgrade -y'"}
wsl -d Ubuntu-20.04 -u root -e 'apt apdate ; apt upgrade -y'
PS> wsl -d Ubuntu-20.04 -u root -e 'apt apdate ; apt upgrade -y'
<em>(runs fine)</em>
</pre>
Thanks for this - I haven't played with WSL in a while (been booting into Xubuntu, a light Ubuntu variant), but I'll have to give it another look.
the UAC things.
I'm getting fed up of Wordpress because I've had problems with hackers and
I'm looking at options for another platform.
I would be fantastic if you could point me in the direction of a good
platform. https://vanzari-parbrize.ro/parbrize/parbrize.php
Comments are closed.
Man, there is so many spelling and grammatical errors in this article.