How Do I Set Up OpenClaw on WSL2 with Daemon Mode? A Complete Guide
Problem
I wanted to run OpenClaw as a 24/7 AI assistant on my Windows machine. I tried the native Windows installation first, but I kept running into issues with Scheduled Tasks, gateway service management, and dependency problems. The service would crash randomly, and getting it to restart automatically was a nightmare.
Then I realized: WSL2 with systemd support is the answer. Here’s the complete setup guide that took me three days to figure out.
Why WSL2 Instead of Native Windows?
I initially tried running OpenClaw directly on Windows. These were my problems:
-
Scheduled Tasks are unreliable - The Windows Task Scheduler doesn’t handle service crashes well. I had to write custom PowerShell scripts just to detect if the service was down.
-
Gateway service management is painful - Starting, stopping, and monitoring the gateway service required manual intervention or complex scripts.
-
Dependency hell - Node.js versions, Sharp native builds, Python paths… every update broke something.
WSL2 with systemd solves all of this. You get proper service management, automatic restarts, and a Linux environment where OpenClaw is designed to run.
Step 1: Install WSL2 with systemd Enabled
First, I needed WSL2 with systemd support. This is critical - without systemd, you can’t run services as daemons.
wsl --installThis installs Ubuntu by default. After the installation completes and you’ve set up your username, verify WSL2 is running:
wsl --list --verboseOutput should show:
NAME STATE VERSIONUbuntu Running 2If it shows version 1, upgrade it:
wsl --set-version Ubuntu 2Step 2: Enable systemd in WSL2
This was the key step I missed initially. Without systemd, there’s no service management.
[boot]systemd=trueCreate or edit this file in your WSL2 instance:
sudo nano /etc/wsl.confAdd the systemd configuration, then restart WSL2:
wsl --shutdownWait a few seconds, then start WSL2 again:
wslVerify systemd is running:
systemctl --versionYou should see systemd version output, not an error.
Step 3: Install OpenClaw
Now install OpenClaw using the official installer:
curl -fsSL https://openclaw.ai/install.sh | bashThe installer will:
- Check your system dependencies
- Install Node.js if needed (LTS version)
- Set up the OpenClaw CLI
- Configure the environment
I ran into an issue where the installer couldn’t find Node.js. If this happens, install it manually:
# Install Node.js 20.x LTScurl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -sudo apt-get install -y nodejs
# Verify installationnode --versionnpm --versionStep 4: Install OpenClaw Gateway as a Service
This is where daemon mode comes in. The gateway service needs to run continuously to handle AI requests.
openclaw gateway installThis command:
- Creates a systemd service file
- Enables the service to start on boot
- Starts the service immediately
Check the service status:
systemctl status openclaw-gatewayYou should see active (running) in the output.
If the service failed to start, check the logs:
journalctl -u openclaw-gateway -n 50Step 5: Run OpenClaw Doctor
After installation, always run the diagnostic tool:
openclaw doctorThis checks:
- Node.js version compatibility
- Service status
- Configuration files
- Network connectivity
- API key validity
The doctor command saved me multiple times. After any update or configuration change, run it to catch issues early.
Common Mistakes I Made
Mistake 1: Skipping systemd
I spent hours trying to run OpenClaw without systemd enabled. I used nohup and screen, but the process would die when WSL2 restarted. systemd is required for true daemon mode.
Mistake 2: Wrong WSL Distro Name
When running wsl --set-version Ubuntu 2, I used the wrong distro name. Check your installed distros:
wsl --list --verboseThe name in the first column is what you use in commands.
Mistake 3: Not Running Doctor After Updates
After updating OpenClaw, I assumed everything would work. It didn’t. Always run:
openclaw doctorThe doctor found a configuration mismatch that broke my gateway service.
Mistake 4: Ignoring Node.js Version
OpenClaw requires Node.js 18.x or higher. I had an old version installed:
# Check your versionnode --version
# If it's old, upgradecurl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -sudo apt-get install -y nodejsMistake 5: Sharp Build Errors
Sharp is a native image processing library. It often fails to build on Windows/WSL2. I got this error:
npm ERR! sharp: Command failednpm ERR! sharp: Prebuilt libvips not foundSolution - install build dependencies:
sudo apt-get install -y build-essential libvips-devnpm rebuild sharpVerify Everything Works
After setup, verify the daemon is running correctly:
# Check service statussystemctl status openclaw-gateway
# Check if port is listeningss -tlnp | grep 3000
# Test the gatewaycurl http://localhost:3000/healthYou should see the gateway responding with a health status.
Why This Matters
With WSL2 + systemd daemon mode, I get:
- 24/7 availability - The service runs in the background without keeping a terminal open
- Automatic restarts - If the gateway crashes, systemd restarts it
- Boot persistence - When Windows restarts, WSL2 starts, and systemd starts OpenClaw
- Resource efficiency - No need for Scheduled Tasks or wrapper scripts
The setup is now set-and-forget. I haven’t touched it in weeks.
Related Knowledge
systemd Service Files
When you run openclaw gateway install, it creates a service file at:
/etc/systemd/system/openclaw-gateway.serviceYou can view it with:
cat /etc/systemd/system/openclaw-gateway.serviceTypical content:
[Unit]Description=OpenClaw Gateway ServiceAfter=network.target
[Service]Type=simpleUser=yourusernameWorkingDirectory=/home/yourusername/.openclawExecStart=/usr/bin/node /home/yourusername/.openclaw/gateway.jsRestart=alwaysRestartSec=10
[Install]WantedBy=multi-user.targetWSL2 Memory Management
WSL2 can consume a lot of memory. Create a .wslconfig file to limit resources:
[wsl2]memory=4GBprocessors=2swap=2GBThis keeps WSL2 from eating all your RAM.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
- 👨💻 OpenClaw Official Site
- 👨💻 WSL2 Documentation
- 👨💻 systemd in WSL2
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments