OpenClaw 完整教程!从安装到使用(官方脚本版)

OpenClaw 完整教程!从安装到使用(官方脚本版)

📝 本教程基于 OpenClaw 官方文档和安装脚本编写,保证准确!


🤔 OpenClaw 是什么?

OpenClaw 是一个个人 AI 助手框架,让你可以在本地运行自己的 AI 助手。

它能帮你做什么?

  • ✅ 聊天问答(微信、QQ、Telegram、Discord 等)
  • ✅ 写文章、写代码
  • ✅ 定时提醒
  • ✅ 自动化任务
  • ✅ 浏览器操作
  • ✅ 文件处理

最大的好处:数据在自己电脑上,隐私安全!


🚀 一键安装(1 条命令)

打开命令行,复制粘贴以下命令:

bash 复制代码
curl -fsSL https://openclaw.ai/install.sh | bash

等待安装完成,过程大约 2-5 分钟。


⚙️ 配置向导详细流程

安装完成后,会自动进入配置向导 (openclaw onboard)。

第 1 步:欢迎界面

bash 复制代码
🦞 Welcome to OpenClaw!
This wizard will help you set up your personal AI assistant.

Enter 继续。


第 2 步:选择 AI 模型

向导会显示可选的 AI 模型:

sql 复制代码
Select your AI provider:
  ○ OpenAI (GPT-4)
  ● Dashscope (通义千问)  ← 推荐国内用户
  ○ Anthropic (Claude)
  ○ Google (Gemini)
  ○ Skip for now

操作方法

  • 方向键选择
  • Enter 确认

模型推荐

  • 国内用户:选 Dashscope(通义千问),速度快,便宜
  • 有 OpenAI:选 OpenAI,模型最强
  • 有 Claude:选 Anthropic,长文本厉害

第 3 步:填写 API Key

选择模型后,输入 API Key:

markdown 复制代码
Enter your Dashscope API Key:
> sk-____________________

如何获取 API Key?

通义千问(Dashscope)

  1. 访问:dashscope.console.aliyun.com/
  2. 登录阿里云账号(没有就注册一个)
  3. 点击左侧"API Key 管理"
  4. 点击"创建新的 API Key"
  5. 复制生成的 Key(以 sk- 开头)
  6. 粘贴到向导里

OpenAI

  1. 访问:platform.openai.com/
  2. 登录或注册
  3. 点击左侧"API Keys"
  4. 点击"Create new secret key"
  5. 复制 Key(以 sk-proj-sk- 开头)

Claude(Anthropic)

  1. 访问:console.anthropic.com/
  2. 登录或注册
  3. 点击"Get API keys"
  4. 点击"Create key"
  5. 复制 Key(以 sk-ant- 开头)

第 4 步:测试连接

向导会测试 API Key 是否有效:

vbnet 复制代码
Testing connection to Dashscope...
✅ Connection successful!
Model: qwen-max
Credits remaining: ¥100.00

如果失败,会提示你重新输入。


第 5 步:选择连接平台

向导会问你要连接哪些聊天平台:

sql 复制代码
Select platforms to connect:
  ○ WhatsApp
  ○ Telegram
  ○ Discord
  ○ Slack
  ○ WeChat (微信)
  ○ QQ
  ○ Skip for now  ← 新手建议先选这个

新手建议

  • 先选 Skip for now(跳过)
  • 等 OpenClaw 运行正常后再配置平台
  • 配置平台需要额外的 Bot ID 或 Token

后续配置 : 运行 openclaw channels add 可以添加平台


第 6 步:安装后台服务

向导会问是否安装后台服务(开机自启):

yaml 复制代码
Install Gateway daemon?
This will start OpenClaw automatically on boot.

  ● Yes (recommended)
  ○ No

建议

  • Yes:OpenClaw 会一直运行,随时可用
  • No:每次需要手动运行 openclaw gateway

后台服务类型

  • macOS:launchd
  • Linux:systemd
  • Windows:WSL2 或手动运行

第 7 步:配置工作目录

向导会设置工作目录:

javascript 复制代码
Workspace location:
> /Users/你的用户名/.openclaw/workspace

Change location? (y/N)

建议

  • 直接按 Enter 使用默认位置
  • 如果需要改,输入 y 然后输入新路径

工作目录用途

  • 存放你的脚本
  • 存放技能文件
  • 存放记忆文件

第 8 步:完成配置

最后,向导会显示总结:

yaml 复制代码
🎉 Setup complete!

Configuration summary:
  • AI Provider: Dashscope (qwen-max)
  • Workspace: ~/.openclaw/workspace
  • Gateway: Running (port 18789)
  • Channels: None (add later with `openclaw channels add`)

What's next?
  • Chat: openclaw agent --message "Hello"
  • Send message: openclaw message send --to xxx --message "Hi"
  • Add channel: openclaw channels add
  • View docs: openclaw docs

Enter 完成配置。


🎉 安装完成

配置完成后,你会看到:

arduino 复制代码
🦞 OpenClaw installed successfully!
✅ Gateway started on port 18789
🤖 AI assistant ready

📚 使用教程

1. 和 AI 对话

最简单的方式

bash 复制代码
openclaw agent --message "你好"

带思考等级

bash 复制代码
# 快速回答
openclaw agent --message "1+1 等于几" --thinking low

# 深度思考
openclaw agent --message "帮我写个 Python 脚本" --thinking high

# 最高思考等级(最贵但最聪明)
openclaw agent --message "分析这个项目的架构" --thinking ultra

连续对话

bash 复制代码
openclaw agent
# 进入交互模式,可以一直聊天
# 输入 exit 退出

2. 发送消息

发送测试消息

bash 复制代码
openclaw message send --message "Hello from OpenClaw"

发送到指定平台

bash 复制代码
# Telegram
openclaw message send --to telegram:@username --message "Hi"

# Discord
openclaw message send --to discord:channel_id --message "Hi"

# 微信(需要配置)
openclaw message send --to wechat:username --message "Hi"

3. WebUI 聊天(推荐新手)

OpenClaw 提供网页版聊天界面(Control UI),比命令行更直观!

方法 1:运行 dashboard 命令

bash 复制代码
openclaw dashboard

这会自动在浏览器打开控制面板。

方法 2:手动访问

  1. 确保网关已启动:openclaw gateway
  2. 打开浏览器
  3. 访问:http://127.0.0.1:18789/

步骤 3:开始聊天

在网页中:

  1. 看到聊天界面
  2. 在输入框输入消息
  3. Enter 或点击发送
  4. AI 会立即回复

WebUI 功能

  • ✅ 实时对话(类似 ChatGPT 界面)
  • ✅ 查看对话历史
  • ✅ 切换模型
  • ✅ 调整思考等级
  • ✅ 导出聊天记录

远程访问(从其他设备访问):

bash 复制代码
openclaw ui --host 0.0.0.0 --port 3000

然后在其他设备访问:http://服务器IP:3000


4. 管理技能(Skills)

查看已安装的技能

bash 复制代码
openclaw skills list

安装新技能

bash 复制代码
openclaw skills install <技能名>

启用/禁用技能

bash 复制代码
openclaw skills enable <技能名>
openclaw skills disable <技能名>

更新技能

bash 复制代码
openclaw skills update

4. 管理扩展(Extensions)

查看已安装的扩展

bash 复制代码
openclaw extensions list

安装扩展

bash 复制代码
openclaw extensions install <扩展名>

5. 管理通道(Channels)

查看已连接的通道

bash 复制代码
openclaw channels list

添加新通道

bash 复制代码
openclaw channels add
# 跟着向导选择平台并配置

移除通道

bash 复制代码
openclaw channels remove <通道名>

🔧 调试和排错

1. 查看状态

查看整体状态

bash 复制代码
openclaw status

输出示例

makefile 复制代码
OpenClaw Status
===============
Gateway: Running ✓
Port: 18789
Model: qwen-max
Channels: 0
Skills: 5
Uptime: 2h 30m

2. 查看日志

查看最近的日志

bash 复制代码
openclaw logs

实时查看日志

bash 复制代码
openclaw logs --follow
# 按 Ctrl+C 退出

查看特定级别的日志

bash 复制代码
# 只看错误
openclaw logs --level error

# 只看警告
openclaw logs --level warn

# 详细模式
openclaw logs --level debug

查看特定时间的日志

bash 复制代码
# 最近 1 小时
openclaw logs --since 1h

# 最近 100 行
openclaw logs --tail 100

3. 运行医生检查

自动检查问题

bash 复制代码
openclaw doctor

输出示例

csharp 复制代码
OpenClaw Doctor
===============
✓ Gateway is running
✓ Configuration is valid
✓ API key is valid
✓ Network connection OK
✓ Node.js version OK (v22.x.x)
⚠ No channels configured (run: openclaw channels add)

1 warning found.

非交互模式(适合脚本):

bash 复制代码
openclaw doctor --non-interactive

4. 重启服务

重启网关

bash 复制代码
openclaw gateway restart

停止网关

bash 复制代码
openclaw gateway stop

启动网关

bash 复制代码
openclaw gateway start

5. 常见问题排查

问题 1:AI 不回复

检查步骤

bash 复制代码
# 1. 检查网关状态
openclaw status

# 2. 检查 API Key
openclaw doctor

# 3. 查看日志
openclaw logs --level error

# 4. 测试连接
openclaw agent --message "test"

问题 2:消息发送失败

检查步骤

bash 复制代码
# 1. 检查通道配置
openclaw channels list

# 2. 检查通道状态
openclaw channels status <通道名>

# 3. 查看通道日志
openclaw logs --grep <通道名>

问题 3:技能不工作

检查步骤

bash 复制代码
# 1. 查看已安装技能
openclaw skills list

# 2. 检查技能是否启用
openclaw skills status <技能名>

# 3. 更新技能
openclaw skills update <技能名>

# 4. 重新安装技能
openclaw skills reinstall <技能名>

📋 完整命令参考

基础命令

命令 说明 示例
openclaw status 查看状态 openclaw status
openclaw doctor 检查问题 openclaw doctor
openclaw logs 查看日志 openclaw logs --follow
openclaw version 查看版本 openclaw version
openclaw help 查看帮助 openclaw help

网关命令

命令 说明 示例
openclaw gateway 启动网关 openclaw gateway --port 18789
openclaw gateway start 启动 openclaw gateway start
openclaw gateway stop 停止 openclaw gateway stop
openclaw gateway restart 重启 openclaw gateway restart

AI 对话命令

命令 说明 示例
openclaw agent 和 AI 对话 openclaw agent --message "你好"
openclaw chat 交互模式 openclaw chat

agent 命令参数

  • --message "文本":发送的消息
  • --thinking low|medium|high|ultra:思考等级
  • --deliver <平台>:发送到指定平台

消息命令

命令 说明 示例
openclaw message send 发送消息 openclaw message send --to xxx --message "Hi"
openclaw message broadcast 群发消息 openclaw message broadcast --message "通知"

配置命令

命令 说明 示例
openclaw onboard 配置向导 openclaw onboard
openclaw config 编辑配置 openclaw config edit
openclaw config show 查看配置 openclaw config show

技能命令

命令 说明 示例
openclaw skills list 列出技能 openclaw skills list
openclaw skills install 安装技能 openclaw skills install weather
openclaw skills enable 启用技能 openclaw skills enable weather
openclaw skills disable 禁用技能 openclaw skills disable weather
openclaw skills update 更新技能 openclaw skills update
openclaw skills uninstall 卸载技能 openclaw skills uninstall weather

扩展命令

命令 说明 示例
openclaw extensions list 列出扩展 openclaw extensions list
openclaw extensions install 安装扩展 openclaw extensions install qqbot
openclaw extensions update 更新扩展 openclaw extensions update

通道命令

命令 说明 示例
openclaw channels list 列出通道 openclaw channels list
openclaw channels add 添加通道 openclaw channels add
openclaw channels remove 移除通道 openclaw channels remove telegram
openclaw channels status 查看状态 openclaw channels status telegram

更新命令

命令 说明 示例
openclaw update 更新 openclaw update
openclaw update --channel 切换版本 openclaw update --channel beta

版本通道

  • stable:稳定版(推荐)
  • beta:测试版
  • dev:开发版

📁 重要文件位置

内容 位置 说明
配置文件 ~/.openclaw/openclaw.json AI 模型、平台配置
日志文件 ~/.openclaw/logs/ 运行日志
工作目录 ~/.openclaw/workspace/ 你的文件和脚本
技能目录 ~/.openclaw/skills/ 安装的技能
扩展目录 ~/.openclaw/extensions/ 安装的扩展
记忆文件 ~/.openclaw/memory/ 对话历史

快速打开配置文件夹

Windows

bash 复制代码
explorer %USERPROFILE%\.openclaw

Mac

bash 复制代码
open ~/.openclaw

Linux

bash 复制代码
cd ~/.openclaw

📚 更多文档

官方文档

视频教程

社区资源


❓ 常见问题

1. 如何卸载?

bash 复制代码
# 1. 停止服务
openclaw gateway stop

# 2. 卸载 OpenClaw
npm uninstall -g openclaw

# 3. 删除配置(可选)
rm -rf ~/.openclaw

2. 如何备份配置?

bash 复制代码
# 备份整个配置目录
cp -r ~/.openclaw ~/.openclaw.backup

# 或只备份配置文件
cp ~/.openclaw/openclaw.json ~/backup/

3. 如何迁移到另一台电脑?

bash 复制代码
# 1. 在新电脑安装 OpenClaw
curl -fsSL https://openclaw.ai/install.sh | bash

# 2. 复制配置文件
cp ~/.openclaw/openclaw.json 新电脑:~/.openclaw/

# 3. 重启服务
openclaw gateway restart

4. 如何查看 API 使用量?

bash 复制代码
# 通义千问
openclaw usage

# 或访问控制台
# https://dashscope.console.aliyun.com/usage

5. 如何切换 AI 模型?

bash 复制代码
# 方法 1:重新运行配置向导
openclaw onboard

# 方法 2:手动编辑配置
openclaw config edit
# 修改 model.provider 和 model.apiKey

6. 如何在后台运行?

bash 复制代码
# macOS/Linux
openclaw gateway --daemon

# Windows(PowerShell)
Start-Process openclaw gateway -WindowStyle Hidden

📝 总结

安装(1 条命令)

bash 复制代码
curl -fsSL https://openclaw.ai/install.sh | bash

配置(跟着向导走)

bash 复制代码
openclaw onboard  # 安装后自动启动

使用(常用命令)

bash 复制代码
# 查看状态
openclaw status

# 和 AI 对话
openclaw agent --message "你好"

# 查看日志
openclaw logs

# 检查问题
openclaw doctor

学习路径

  1. ✅ 安装完成
  2. ✅ 运行 openclaw agent 测试对话
  3. ✅ 配置一个聊天通道(如 Telegram)
  4. ✅ 安装几个实用技能
  5. ✅ 探索自动化功能

总耗时:15-30 分钟

开始使用吧! 💪


教程版本:v2.0(完整版)| 最后更新:2026-03-05

参考文档:docs.openclaw.ai

官方安装脚本:openclaw.ai/install.sh

社区:discord.gg/clawd

相关推荐
大雨还洅下1 小时前
前端手写: new操作符
前端
hqk1 小时前
鸿蒙项目实战:手把手带你实现 WanAndroid 布局与交互
android·前端·harmonyos
是糖糖啊2 小时前
OpenClaw 从零到一实战指南(飞书接入)
前端·人工智能·后端
Despupilles2 小时前
第三篇、基本骨架结构
前端
swipe2 小时前
从原理到手写:彻底吃透 call / apply / bind 与 arguments 的底层逻辑
前端·javascript·面试
踩着两条虫2 小时前
从设计稿到代码:VTJ.PRO 的 AI 集成系统架构解析
前端·vue.js·人工智能
Mapmost2 小时前
从“雕琢”到“生成”:AIGC正在重塑数字孪生世界
前端
掘金一周3 小时前
Claude Code 换成了Kimi K2.5后,我再也回不去了 | 掘金一周 3.5
前端·人工智能·agent
JasonYin3 小时前
ViewModel 知识体系思维导图
前端