NOTE: If you have Windows 11 there is now an official way to do this in WSL 2, use it if possible - see MS post here (WINDOWS 11 ONLY)
This guide will enable systemd
to run as normal under WSL 2. This will enable services like microk8s
, docker
and many more to just work
during a WSL session. Note: this was tested on Windows 10 Build 2004, running Ubuntu 20.04 LTS in WSL 2.
-
To enable
systemd
under WSL we require a tool calledsystemd-genie
-
Copy the contents of
install-sg.sh
to a new file/tmp/install-sg.sh
:cd /tmp wget --content-disposition \ "https://gist.githubusercontent.com/djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950/raw/952347f805045ba0e6ef7868b18f4a9a8dd2e47a/install-sg.sh"
-
Make it executable:
chmod +x /tmp/install-sg.sh
-
Run the new script:
/tmp/install-sg.sh && rm /tmp/install-sg.sh
-
Exit the WSL terminal and shutdown the WSL env:
wsl --shutdown
-
To open a new WSL terminal with
systemd
enabled, run:wsl genie -s
-
Prove that it works:
sudo systemctl status time-sync.target
bobby@NewBee:/mnt/c/WINDOWS/system32/tmp$ sudo apt install dotnet-runtime-5.0
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
dotnet-runtime-5.0 is already the newest version (5.0.17-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
bobby@NewBee:/mnt/c/WINDOWS/system32/tmp$ dotnet --list-runtimes
Microsoft.AspNetCore.App 6.0.8 [/usr/lib/dotnet/dotnet6-6.0.108/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.8 [/usr/lib/dotnet/dotnet6-6.0.108/shared/Microsoft.NETCore.App]
bobby@NewBee:/mnt/c/WINDOWS/system32/tmp$ genie
You must install or update .NET to run this application.
App: /usr/libexec/genie/genie
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '5.0.0' (x64)
.NET location: /usr/lib/dotnet/dotnet6-6.0.108
The following frameworks were found:
6.0.8 at [/usr/lib/dotnet/dotnet6-6.0.108/shared/Microsoft.NETCore.App]
Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed
To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=5.0.0&arch=x64&rid=ubuntu.22.04-x64
I followed the steps but got dotnet runtime error. If I only install runtime-5.0, my
dotnet
command broken because it said/usr/lib/dotnet/dotnet6-6.0.108
not exist. Can anyone help me on the dotnet runtime issue?