How to Enable systemd in WSL2 — Setup, Use Cases, and Troubleshooting¶
Audience: Developers using WSL2 who want to use systemctl (basic Linux knowledge required)
Key Points¶
- Just 2 lines of config Add a
[boot]section to/etc/wsl.confand restart - Docker & service management unlocked Use
systemctl enableto auto-start services - Startup delays are fixable Mask unnecessary services to speed things up
What "System has not been booted with systemd" Means¶
Run systemctl status in WSL2, and you'll hit this error:
System has not been booted with systemd as init system (PID 1).
Can't operate.
Failed to connect to bus: Host is down
WSL2 ships with systemd disabled by default. WSL's own init process runs as PID 1, so every systemd-dependent command fails.
The fix is a single config change. Before WSL 0.67.6 (September 2022), third-party tools like genie or Distrod were needed. Now it's officially supported.
Check Your Prerequisites¶
Before configuring, verify your WSL version:
wsl --version
If this command fails, you're on the legacy "inbox" WSL. Run wsl --update to get the Store version.
| Requirement | Condition |
|---|---|
| WSL version | 0.67.6+ (Store version) |
| Windows 11 | Store WSL installed |
| Windows 10 | 21H1+ with KB5020030 |
| WSL generation | WSL 2 (WSL 1 is not supported) |
Check which WSL version your distro is running:
wsl -l -v
The VERSION column should show 2.
Enable systemd in 3 Steps¶
Step 1: Edit wsl.conf¶
sudo nano /etc/wsl.conf
Add the following:
[boot]
systemd=true
If the file already has content, append the [boot] section.
Step 2: Restart WSL¶
Shut down WSL completely from PowerShell:
wsl.exe --shutdown
Then reopen WSL. The config change requires about 8 seconds after shutdown to take effect.
Step 3: Verify¶
systemctl status
If you see State: running, you're good. Check the service list:
systemctl list-unit-files --type=service | head -20
Ubuntu 23.04+ has systemd enabled by default
If you installed the latest Ubuntu via wsl --install, systemd is already active. Other distros like Debian and Kali require manual setup.
What You Can Do After Enabling systemd¶
With systemd running, WSL2 becomes a much more capable Linux environment.
Manage Docker via systemctl¶
Run Docker Engine directly in WSL2 — no Docker Desktop needed.
sudo systemctl enable docker.service
sudo systemctl start docker
docker run hello-world
Auto-start Services on WSL Boot¶
Launch web servers and databases automatically when WSL starts:
sudo systemctl enable nginx
sudo systemctl enable postgresql
Other Use Cases¶
- snap: The
snapddaemon requires systemd, enabling snap package installs - MicroK8s: Run lightweight Kubernetes on WSL2
- Custom services: Manage your own daemons with Unit files
Troubleshooting¶
Slow Startup After Enabling systemd¶
This is the most common issue. WSL may take tens of seconds to start.
Cause: Services like systemd-networkd-wait-online.service are waiting for timeouts.
# Identify the bottleneck
systemd-analyze blame | head -10
# Mask unnecessary services (stronger than disable)
sudo systemctl mask systemd-networkd-wait-online.service
sudo systemctl mask multipathd.socket
Changes take effect after wsl --shutdown and restart.
Still Getting the Error¶
If systemctl still fails, check these in order:
- Typo in wsl.conf: Verify
systemd=truespelling and[boot]section name - Didn't restart properly: Run
wsl --shutdown(closing the terminal isn't enough) - Running WSL 1: Check
wsl -l -v— VERSION must be 2 - Legacy WSL: If
wsl --versionfails, runwsl --update
Summary¶
- Add
[boot] systemd=truetowsl.confand restart — that's all it takes - Docker, nginx, and other services work with
systemctlout of the box - Fix startup delays with
systemd-analyze blame→mask
With systemd enabled, WSL2 becomes nearly equivalent to a native Linux environment. You can replicate your server setup directly in WSL2, minimizing the gap between development and production.