There are two questions you seem to have asked:
- From the question title: Why Systemd is disabled in WSL
- From the question body: How to enable Systemd in WSL
The answer to "Why" is because, historically, the WSL architecture required that its init
process be PID 1. Systemd also requires that it run as PID 1 for pretty much all of its functionality (other than some small subsets like tmpfiles
).
As to how, there are some answers here already, obviously, as well as some new answers (see below). To avoid repeating these in detail across some 35+ Systemd-related questions here on Stack Overflow, a Community Wiki answer has been posted on the question Enable systemd in WSL 2.
To summarize:
- Option 1: Upgrade WSL to the latest version (if supported by your system) and opt-in to the Systemd feature
- Option 2: Run a Systemd-helper script designed for WSL2
- Option 3: Manually run Systemd in its own namespace
- Alternative 1: SysVInit scripts (e.g.
sudo service <service_name> start
) where available
- Alternative 2: Manually configuring and running the service
- Alternative 3: Docker
Please see the Community Wiki for more details.
While new, individual additional answers are welcome, it is hoped that they don't repeat any of the options above. It is also encouraged that if new information is available, it is edited into the Community Wiki.