菜鸟AI - 让提示词生成更简单! 全站导航 全站导航
AI工具安装 新手教程 进阶教程 辅助资源 AI提示词 热点资讯 技术资讯 产业资讯 内容生成 模型技术 AI信息库

已有账号?

首页 > AI教程 > OpenClaw搭建推荐:全网最简单避坑步骤
新手教程 OpenClaw搭建

OpenClaw搭建推荐:全网最简单避坑步骤

2026-06-02
阅读 0
热度 0
作者 菜鸟AI编辑部
摘要

摘要

OpenClaw是一款多平台本地AI助手,支持Windows、macOS、Linux及WSL。需Node js≥22 0 0、内存≥2GB。

一、前言

OpenClaw(小龙虾)作为本地 AI 工具,安装环节容易中断——命令未识别、端口冲突、编译报错频发。本文覆盖 Windows、macOS、Linux、WSL 全平台,提供精简安装流程与完整报错解决方案,确保一次成功。

OpenClaw 全网最简单搭建步骤+最全避错坑位指南

二、环境要求(必读)

  • Node.js 版本:需 ≥ 22.0.0,低于此版本极易报错。
  • 内存:至少 2GB,建议 4GB 以上。
  • 系统:Windows 10+、macOS 12+、Linux(Ubuntu 20.04+)。
  • 工具:Git、pnpm(推荐)、curl,提前备好。

三、四种安装方法(新手优先选方式一)

方式一:一键脚本(全自动,强烈推荐)

Windows 管理员 PowerShell

# 设置执行策略
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
# 国内镜像一键安装
iwr -useb https://open-claw.org.cn/install-cn.ps1 | iex

macOS / Linux / WSL

# 国内镜像一键安装
curl -fsSL https://open-claw.org.cn/install-cn.sh | bash

安装后验证

openclaw --version
# 显示版本号即成功

方式二:npm/pnpm 手动安装(有 Node 环境首选)

# 配置国内镜像加速
npm config set registry https://registry.npmmirror.com
# 全局安装
npm install -g openclaw@latest
# 初始化配置
openclaw onboard

方式三:源码编译(开发者 / 二次开发)

# 克隆 Gitee 国内镜像
git clone https://gitee.com/OpenClaw-CN/openclaw-cn.git
cd openclaw-cn
# 安装 pnpm
npm install -g pnpm
# 安装依赖并构建
pnpm install
pnpm ui:build
pnpm build
# 创建全局链接
pnpm link --global
# 初始化并安装守护进程
openclaw onboard --install-daemon

方式四:Docker 部署(服务器 / 隔离环境)

# 拉取镜像
docker pull openclaw/openclaw:latest
# 启动容器
docker run -d --name openclaw -p 18789:18789 openclaw/openclaw:latest

四、初始化与启动

# 配置向导(设置 API Key、端口、权限)
openclaw onboard
# 启动网关
openclaw gateway start
# 查看状态
openclaw gateway status
# 访问 Web UI
http://localhost:18789

五、常见错误排查指南(按报错定位)

错误 1:命令不存在(openclaw: command not found)

  • 原因:npm 全局路径未加入系统 PATH
  • 解决方法:
# 查看 npm 全局路径
npm config get prefix
# Windows:将该路径添加到系统环境变量
# macOS / Linux:
echo 'export PATH=$(npm config get prefix)/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

错误 2:Windows 执行策略禁止运行脚本

  • 报错:cannot be loaded because running scripts is disabled
  • 解决方法:管理员 PowerShell 执行
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force

错误 3:端口 18789 被占用

  • 报错:address already in use
  • 解决方法:
# Windows
netstat -ano | findstr :18789
taskkill /F /PID 进程ID
# macOS / Linux
lsof -i :18789
kill -9 进程ID
# 或修改端口
openclaw config set gateway.port 18790
openclaw gateway restart

错误 4:node-llama-cpp 编译失败

  • 原因:缺少 C++ 编译环境
  • 解决方法:
    • Windows:安装 VS Build Tools,勾选 C++ 生成工具
    • macOS:xcode-select --install
    • Linux:sudo apt install build-essential cmake -y

错误 5:npm 安装权限错误(EACCES)

  • 解决方法:
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

错误 6:sharp 安装失败(macOS)

  • 解决方法:
SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install -g openclaw@latest

错误 7:Gateway 启动失败 / 服务异常

  • 解决方法:
# 停止服务
openclaw gateway stop
# 强制清理进程
pkill -9 -f openclaw-gateway
# 强制重启
openclaw gateway run --force
# 查看日志
# Windows:C:\Users\用户名\.openclaw\logs
# macOS / Linux:~/.openclaw/logs

错误 8:路径含中文 / 空格导致异常

  • 规则:安装目录、工作路径禁止包含中文、空格、特殊字符
  • 示例:D:\AI\openclaw ✅;D:\我的文件\open claw

错误 9:WSL2 运行异常

  • 解决方法:
# 安装依赖
sudo apt install pulseaudio -y
export SDL_AUDIODRIVER=pulseaudio

六、常用命令速查

openclaw --version        # 查看版本
openclaw onboard          # 初始化配置
openclaw gateway start    # 启动网关
openclaw gateway stop     # 停止网关
openclaw gateway restart  # 重启网关
openclaw gateway status   # 查看状态
openclaw doctor           # 自动检测环境问题
npm update -g openclaw@latest  # 升级版本

七、核心要点

  1. 新手直接使用国内一键脚本,99% 一次通过。
  2. 报错优先排查Node 版本、PATH、端口、编译环境,这几项覆盖大多数问题。
  3. 路径避免中文,权限给足,日志是最佳调试工具——遇到问题先看日志,比猜测高效得多。

来源:互联网

免责声明

本网站新闻资讯均来自公开渠道,力求准确但不保证绝对无误,内容观点仅代表作者本人,与本站无关。若涉及侵权,请联系我们处理。本站保留对声明的修改权,最终解释权归本站所有。

同类文章推荐

相关文章推荐

更多