Enabling Linux Services on WSL
Introduction
To run services like systemd
on WSL, you need to ensure that your WSL environment is correctly configured. This guide provides step-by-step instructions for enabling Linux services on WSL.
Prerequisites
- Windows 10 (version 2004 and higher) or Windows 11
- WSL 2 installed and set as the default version
- Administrative privileges to update WSL and edit configuration files
Step 1: Update WSL
Ensure your WSL installation is up to date to enable full systemd
support.
- Open Command Prompt or PowerShell as Administrator.
- Run the following command to update WSL:
wsl --update
Step 2: Verify WSL Version
Ensure that your Linux distribution is using WSL 2, as systemd
support is only available in WSL 2.
-
Check the version of your WSL distributions:
wsl --list --verbose
-
If your distribution is not using WSL 2, upgrade it:
wsl --set-version <DistroName> 2
Replace
<DistroName>
with the name of your Linux distribution (e.g.,Ubuntu
).
Step 3: Enable Systemd
Enable systemd
to manage Linux services within WSL.
-
Open your Linux distribution (e.g.,
Ubuntu
) in WSL. -
Edit the WSL configuration file:
sudo nano /etc/wsl.conf
-
Add the following lines:
[boot] systemd=true
-
Save and close the file (Ctrl+O, Enter, Ctrl+X).
-
Restart WSL to apply the changes:
wsl --shutdown
Then reopen your Linux distribution.
Step 4: Verify Systemd is Enabled
Confirm that systemd
is active in your WSL distribution.
- Run the following command to check the status of
systemd
:systemctl --version
If the command outputs the
systemd
version, it is successfully enabled.
Troubleshooting
Error: systemctl: command not found
-
Ensure you have edited the
/etc/wsl.conf
file correctly and added the[boot]
section withsystemd=true
. -
Restart WSL with:
wsl --shutdown