一、前置系统要求
基础环境
- Node.js:最低
22.14+,推荐 24.x LTS - 磁盘:空闲空间 ≥ 500MB
- 网络:全程需要联网下载依赖 / 镜像
检查 Node 版本
打开终端 / 命令行执行:
bash
运行
node --version
版本不达标,建议用版本管理器 nvm 安装对应版本:
- Windows:使用 nvm-windows
- macOS/Linux:使用 nvm
bash
运行
# 通用安装指定版本
nvm install 24
nvm use 24
二、Windows 系统安装(两种方案)
方案一:WSL2 安装(推荐,兼容性最佳)
WSL2 模拟完整 Linux 环境,绝大多数插件、沙箱、技能都能正常运行。
- 安装 WSL2 以管理员身份打开 PowerShell,执行: powershell
wsl --install执行完成后重启电脑,系统自动安装默认 Ubuntu。 - 安装 OpenClaw 开始菜单打开
Ubuntu终端,执行一键安装脚本: bash运行curl -fsSL https://openclaw.ai/install.sh | bash - 服务管理(Linux 体系命令) bash运行
# 注册开机自启服务 openclaw gateway install # 查看状态 openclaw gateway status # 启动/停止/重启 openclaw gateway start openclaw gateway stop openclaw gateway restart
小贴士:文件尽量放在 WSL 内部
/home/用户名,不要用/mnt/c挂载 Windows 目录,性能更高。
方案二:原生 Windows 安装(不使用 WSL2)
打开 PowerShell(普通 / 管理员均可),执行:
powershell
iwr -useb https://openclaw.ai/install.ps1 | iex
服务管理(依托系统计划任务)
powershell
# 注册为系统服务、开机自启
openclaw gateway install
# 状态查询
openclaw gateway status
# 启停重启
openclaw gateway start
openclaw gateway stop
openclaw gateway restart
Windows 常见问题解决
- PowerShell 执行策略报错 powershell
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned - 18789 端口被占用 powershell
netstat -ano | findstr 18789 - 防火墙拦截:手动放行
18789端口。
三、macOS 安装(最简单,一键部署)
- 打开「终端」,执行一键安装脚本:
bash
运行
curl -fsSL https://openclaw.ai/install.sh | bash
脚本自动适配 Intel / Apple Silicon 芯片,自动配置环境变量。
- 服务管理(launchd 开机自启)
bash
运行
# 注册后台服务、开机自动运行
openclaw gateway install
# 查看运行状态
openclaw gateway status
# 启动/停止/重启
openclaw gateway start
openclaw gateway stop
openclaw gateway restart
macOS 注意事项
- 首次运行弹出安全拦截:前往 系统设置 → 隐私与安全性 允许运行;
- 若使用 Homebrew 安装 Node,确保
node命令能全局调用。
四、Linux 安装(主力生产环境)
支持 Ubuntu / Debian / CentOS / Rocky 等主流发行版。
1. 一键安装
bash
运行
# 先安装 curl(无则执行)
sudo apt install curl -y # Ubuntu/Debian
sudo yum install curl -y # CentOS/RHEL
# 执行安装脚本
curl -fsSL https://openclaw.ai/install.sh | bash
2. 服务管理(systemd)
bash
运行
# 注册系统服务
openclaw gateway install
# 查看状态
openclaw gateway status
# 启停重启
openclaw gateway start
openclaw gateway stop
openclaw gateway restart
3. 服务器 7×24 持久运行(关键)
Linux 默认用户退出登录后服务会终止,启用 linger 保持后台常驻:
bash
运行
sudo loginctl enable-linger 你的用户名
Linux 注意事项
- 系统自带 Node 版本普遍偏低,务必使用 nvm 升级到 22.14+ / 24;
- 开启 SELinux 的服务器,需手动放行 18789 端口。
五、Docker 容器安装(隔离部署,通用全平台)
适合喜欢容器化、快速部署、不想配置本地环境的用户,Windows/macOS/Linux 通用。
方式 1:单行命令快速启动
bash
运行
docker run -d \
--name openclaw \
-p 18789:18789 \
-v openclaw-data:/root/.openclaw \
--restart unless-stopped \
openclawai/openclaw:latest
方式 2:docker-compose(推荐,便于维护)
- 新建
docker-compose.yml文件:
yaml
version: '3.8'
services:
openclaw:
image: openclawai/openclaw:latest
container_name: openclaw
restart: unless-stopped
ports:
- "18789:18789"
volumes:
- openclaw-data:/root/.openclaw
environment:
- TZ=Asia/Shanghai
volumes:
openclaw-data:
- 启动容器:
bash
运行
docker-compose up -d
Docker 运维命令
bash
运行
# 查看容器状态
docker ps | grep openclaw
# 停止/重启
docker stop openclaw
docker restart openclaw
# 查看日志
docker logs openclaw
Docker 注意事项
- 国内拉取镜像慢:配置 Docker 镜像加速器;
- 数据全部存放在数据卷
openclaw-data,重装容器不会丢失配置 / 会话; - 更新版本:先
docker pull openclawai/openclaw:latest,再重建容器。
六、安装验证(全平台通用)
任意终端执行以下命令,确认安装成功:
bash
运行
# 查看版本
openclaw --version
# 全面环境诊断(推荐)
openclaw doctor
# 查看网关运行状态
openclaw gateway status
openclaw doctor 会自动检测 Node 版本、依赖、端口、配置,有问题会给出修复指引。
七、各平台服务能力对照表
表格
| 运行平台 | 服务管理方式 | 开机自启 | 后台常驻 |
|---|---|---|---|
| macOS | launchd | ✅ 自动 | ✅ 自动 |
| Linux | systemd | ✅ | ✅ 需执行 enable-linger |
| Windows WSL2 | systemd | ✅ | ⚠️ 需配置 WSL 自启 |
| Windows 原生 | 系统计划任务 | ✅ 自动 | ✅ 自动 |
| Docker | 容器重启策略 | ✅ 自动 | ✅ 自动 |
八、常见问题汇总
- Node 版本过低 统一使用 nvm 安装 24 版本,不要使用系统自带旧版。
- 端口 18789 冲突 关闭占用端口的程序,或修改 OpenClaw 监听端口。
- Linux 无 systemd(Alpine 等精简系统) 改用 PM2 托管进程。
- WSL2 网络无法访问 Windows 直接使用
localhost:18789访问即可。