13g10n
Home

Using systemd in WSL

When trying to use systemd to start and manage services on WSL, I encountered the error "System has not been booted with systemd as init system (PID 1).". Previously, we could not use systemd on WSL, which was very sad, but starting with version WSL 0.67.6 this opportunity became available.

Here and below I use a combination of Windows 11 + WSL 2 + Ubuntu.

First of all, let's make sure that we have WSL updated to the latest version. To do this, enter in the Windows terminal:

Windows
wsl --update

Next, start any installed distribution and open the internal file /etc/wsl.conf in any text editor.

Ubuntu
sudo nano /etc/wsl.conf

We need to add a boot section, if it does not exist, and use the self-explanatory systemd setting in it:

/etc/wsl.conf
[boot]
systemd=true

Save the file and restart WSL.

Windows
wsl --shutdown

After this, systemd in WSL starts working as expected and we can add and manage services.

I never thought that I would write this kind of notes, but Windows 11 + WSL 2 is really a powerful thing, which I can safely recommend to all developers suffering from desktop Linux distributions.

WSLWindowsLinuxsystemd