Skip to content

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:

  1. 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.

  2. Gateway service management is painful - Starting, stopping, and monitoring the gateway service required manual intervention or complex scripts.

  3. 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.

PowerShell (Administrator)
wsl --install

This installs Ubuntu by default. After the installation completes and you’ve set up your username, verify WSL2 is running:

PowerShell
wsl --list --verbose

Output should show:

wsl list output
NAME STATE VERSION
Ubuntu Running 2

If it shows version 1, upgrade it:

Upgrade WSL version
wsl --set-version Ubuntu 2

Step 2: Enable systemd in WSL2

This was the key step I missed initially. Without systemd, there’s no service management.

/etc/wsl.conf
[boot]
systemd=true

Create or edit this file in your WSL2 instance:

Terminal window
sudo nano /etc/wsl.conf

Add the systemd configuration, then restart WSL2:

PowerShell
wsl --shutdown

Wait a few seconds, then start WSL2 again:

Terminal window
wsl

Verify systemd is running:

Terminal window
systemctl --version

You should see systemd version output, not an error.

Step 3: Install OpenClaw

Now install OpenClaw using the official installer:

WSL2 Terminal
curl -fsSL https://openclaw.ai/install.sh | bash

The 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:

Terminal window
# Install Node.js 20.x LTS
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
# Verify installation
node --version
npm --version

Step 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.

WSL2 Terminal
openclaw gateway install

This command:

  1. Creates a systemd service file
  2. Enables the service to start on boot
  3. Starts the service immediately

Check the service status:

Terminal window
systemctl status openclaw-gateway

You should see active (running) in the output.

If the service failed to start, check the logs:

Terminal window
journalctl -u openclaw-gateway -n 50

Step 5: Run OpenClaw Doctor

After installation, always run the diagnostic tool:

Terminal window
openclaw doctor

This 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:

Terminal window
wsl --list --verbose

The 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:

Terminal window
openclaw doctor

The 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:

Terminal window
# Check your version
node --version
# If it's old, upgrade
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs

Mistake 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 failed
npm ERR! sharp: Prebuilt libvips not found

Solution - install build dependencies:

Terminal window
sudo apt-get install -y build-essential libvips-dev
npm rebuild sharp

Verify Everything Works

After setup, verify the daemon is running correctly:

Terminal window
# Check service status
systemctl status openclaw-gateway
# Check if port is listening
ss -tlnp | grep 3000
# Test the gateway
curl http://localhost:3000/health

You should see the gateway responding with a health status.

Why This Matters

With WSL2 + systemd daemon mode, I get:

  1. 24/7 availability - The service runs in the background without keeping a terminal open
  2. Automatic restarts - If the gateway crashes, systemd restarts it
  3. Boot persistence - When Windows restarts, WSL2 starts, and systemd starts OpenClaw
  4. Resource efficiency - No need for Scheduled Tasks or wrapper scripts

The setup is now set-and-forget. I haven’t touched it in weeks.

systemd Service Files

When you run openclaw gateway install, it creates a service file at:

Terminal window
/etc/systemd/system/openclaw-gateway.service

You can view it with:

Terminal window
cat /etc/systemd/system/openclaw-gateway.service

Typical content:

[Unit]
Description=OpenClaw Gateway Service
After=network.target
[Service]
Type=simple
User=yourusername
WorkingDirectory=/home/yourusername/.openclaw
ExecStart=/usr/bin/node /home/yourusername/.openclaw/gateway.js
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target

WSL2 Memory Management

WSL2 can consume a lot of memory. Create a .wslconfig file to limit resources:

%UserProfile%.wslconfig
[wsl2]
memory=4GB
processors=2
swap=2GB

This 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:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments