Run Linux programs in Windows

Setting Up WSL with Systemd


Windows Subsystem for Linux (WSL) allows you to run a Linux environment directly on Windows without the need for a virtual machine. This guide will walk you through the process of setting up WSL and enabling systemd.

Enabling systemd in WSL2 provides a more complete Linux environment, closer to a traditional Linux system. It allows for better service management, improved compatibility with certain applications, and enables features like systemctl commands. This setup is particularly useful for developers who need a more robust Linux environment within Windows.

  1. Enable WSL and Virtual Machine Platform: In PowerShell (Admin):

    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
    
  2. Restart your computer, set WSL 2 as default and install Ubuntu:

    wsl --set-default-version 2
    wsl --install -d Ubuntu
    
  3. Launch WSL, set up your account when prompted & update packages:

    sudo apt update && sudo apt upgrade -y
    
  4. Enable systemd:

    Edit /etc/wsl.conf:

    sudo nano /etc/wsl.conf
    

    Add:

    [boot]
    systemd=true
    
  5. Restart WSL:

    exit
    wsl --shutdown
    wsl
    
  6. Verify systemd is running:

    ps --no-headers -o comm 1
    

    This should output “systemd”