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.
First of all, let's make sure that we have WSL updated to the latest version. To do this, enter in the Windows terminal:
Next, start any installed distribution and open the internal file /etc/wsl.conf in any text editor.
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:
Save the file and restart WSL.
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.