As the quest for a perfect development environment continues, with me jumping from:

  • XAMPP + XPM (shameless plug: I wrote XPM 😉)
  • Laragon (which sucked so much)
  • VirtualBox/HyperVM-based virtual machines (whose setup took more than my actual dev time)

...I'm now exploring the new Windows Subsystem for Linux. So far, aside from a few hacks it works great.

But systemd sucks

It doesn't, but you're free to be wrong at your own will. 😎

Even if you do think it sucks (and I'm sure there are merits to those claims, especially with it being a total feature creep), Ubuntu (and others like Debian and CentOS) expects systemd for setting up packages, especially PHP-FPM and MariaDB.

Technically, these won't work because systemd isn't PID 1. You won't be able to start MariaDB and the other services.

Enter genie

Simply put, genie allows systemd to run inside WSL 2. You can learn more about the project at their GitHub page.

With Genie and a few tricks for setting up aliases, it fixes some of the problems.

Let's set it up.

Note that these instructions have been tested on Ubuntu 18.04 as of writing. There is no systemd-genie repo for 20.04 yet, and while you can build it yourself, who really has the time?

Install .NET Core

Genie depends on dotnet-runtime-3.0, so we should set up the Microsoft repository:

wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt update -y

These were taken from the .NET Core page found here and you should check this yourself as URLs tend to change (even though they shouldn't).

After setting up the repository, you don't need to install it since systemd-genie requires it as a dependency anyway.

Set up systemd-genie

Add the repository using the following command:

curl -s https://packagecloud.io/install/repositories/arkane-systems/wsl-translinux/script.deb.sh | sudo bash

Instructions taken from the Arkane Systems packagecloud. Again, check this regularly as instructions may be different than from when this article was written.

Finally, set up systemd-genie:

sudo apt install systemd-genie -y

Once installed, commands that rely on systemd (such as systemctl and in some cases apt) should be prefixed with genie -c, like so:

sudo genie -c systemctl restart php7.4-fpm

But what if I don't want to type genie -c every time?

Bash aliases to the rescue

Edit /etc/bash.bashrc and add the following lines to the end of the file:

alias systemctl="genie -c systemctl"
alias apt="genie -c apt"
alias apt-get="genie -c apt-get"

Now, log out of all your active terminal sessions. On your next login to the WSL terminal, systemctl and apt now work as expected without having to prefix them with genie -c every time:

It works!