OpenClaw Linux 安装指南:在 Ubuntu、Debian、Fedora 和 Raspberry Pi 上安装
OpenClaw 的完整 Linux 安装指南。涵盖 Ubuntu、Debian、Fedora、ARM64 支持、Raspberry Pi 设置和用于始终在线访问的 Cloudflare 隧道。
Quick Answer
在 Linux 上安装 OpenClaw:`curl -fsSL https://openclaw.ai/install.sh | bash` 或 `npm i -g openclaw`。适用于 Ubuntu、Debian、Fedora 和 Raspberry Pi。使用 systemd 提供始终在线的服务。
简介
Linux 是运行 OpenClaw 的优秀平台,特别是对于始终在线的服务器和 Raspberry Pi 部署。本指南涵盖了流行的 Linux 发行版(包括 Ubuntu、Debian、Fedora 和 Raspberry Pi OS)上的安装,以及 ARM64 支持和 systemd 服务配置。
有关一般安装说明,请参阅我们的完整安装指南。
系统要求
支持的发行版
- Ubuntu 20.04+(推荐 LTS)
- Debian 11+(Bullseye 或更高版本)
- 软呢帽 34+
- Raspberry Pi 操作系统(基于 Debian)
- Arch Linux(通过 AUR 或手动安装)
- 其他基于 Debian/Ubuntu 的发行版
硬件要求
- RAM — 建议 2GB+(Raspberry Pi 至少 1GB)
- 存储 — 500MB+ 用于安装,额外的内存/数据空间
- CPU — x86_64 或 ARM64 架构
- 网络 — 用于 API 调用和更新的互联网连接
软件先决条件
- Node.js 18+ — 可以由单行安装程序自动安装
- curl — 通常是预安装的
- git — 可选,用于从源代码进行可破解安装
- systemd — 用于服务管理(最现代的发行版)
安装方法
方法 1:单行安装(推荐)
在 Linux 上安装 OpenClaw 最简单的方法:
curl -fsSL https://openclaw.ai/install.sh | bash
该脚本自动:
- 检测您的 Linux 发行版
- 如果缺少 Node.js,则安装(通过 NodeSource 或分发包管理器)
- 通过 npm 在全球范围内安装 OpenClaw
- 设置必要的权限
- 验证安装
注意: 系统可能会提示您输入密码 (sudo) 以安装 Node.js 或系统软件包。
方法2:npm安装
如果您已经安装了 Node.js:
npm i -g openclaw
首先验证 Node.js 版本:
node --version
应该是 v18.0.0 或更高版本。
方法 3:特定于发行版的包
Ubuntu/Debian(通过 apt)
某些发行版可能提供 OpenClaw 软件包:
# Add repository (if available)
curl -fsSL https://openclaw.ai/repo/deb/pubkey.gpg | sudo gpg --dearmor -o /usr/share/keyrings/openclaw.gpg
echo "deb [signed-by=/usr/share/keyrings/openclaw.gpg] https://openclaw.ai/repo/deb stable main" | sudo tee /etc/apt/sources.list.d/openclaw.list
# Install
sudo apt update
sudo apt install openclaw
注意: 官方软件包可能尚未提供。检查 docs.openclaw.ai 了解最新的安装方法。
Fedora(来自 dnf)
# Add repository (if available)
sudo dnf install openclaw
Arch Linux(通过 AUR)
yay -S openclaw
# or
paru -S openclaw
方法 4:可破解安装(从源代码)
对于想要修改源代码的开发者:
git clone https://github.com/openclaw/openclaw.git
cd openclaw
npm install
npm run build
然后运行:
npm run openclaw onboard
或者全局链接:
sudo npm link --global
安装 Node.js
Ubuntu/Debian
选项 1:NodeSource 存储库(推荐)
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
选项 2:分发包
sudo apt update
sudo apt install nodejs npm
注意: 分发包可能已过时。 NodeSource 提供了较新的版本。
选项 3:nvm(节点版本管理器)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install 18
nvm use 18
软呢帽
sudo dnf install nodejs npm
或者使用 NodeSource:
curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
sudo dnf install -y nodejs
树莓派 (ARM64/ARMv7)
Raspberry Pi 操作系统(基于 Debian)
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
对于 ARMv7(32 位),NodeSource 可能没有软件包。使用分发包或从源代码构建。
替代方案:通过 nvm 安装
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install 18
安装后设置
安装完成后,配置OpenClaw:
openclaw onboard
此交互式设置涵盖:
1.AI模型配置
选择您的人工智能提供商:
AnthropicClaude:
- Claude 3.5 十四行诗(推荐)
- Claude 3 部作品
- Claude 4
从 console.anthropic.com 获取您的 API 密钥。
OpenAI GPT:
- GPT-4o
- GPT-4 涡轮增压
- GPT-4.1
从 platform.openai.com 获取您的 API 密钥。
本地型号:
- Ollama(本地运行,无需 API 密钥)
- LM工作室
- 最小最大
2.Linux权限
OpenClaw 可能需要权限:- 文件系统 — 对 ~/.openclaw 的读/写访问
- 网络 — 用于 API 调用和聊天桥
- 系统命令 — 如果使用系统控制功能
3. 防火墙配置
允许 OpenClaw 通过防火墙:
UFW (Ubuntu/Debian):
sudo ufw allow 3000/tcp
firewalld (Fedora/RHEL):
sudo firewall-cmd --add-port=3000/tcp --permanent
sudo firewall-cmd --reload
运行 OpenClaw
启动服务器
openclaw
这将启动本地服务器并连接所有配置的集成。
在后台运行
使用 nohup:
nohup openclaw > ~/.openclaw/logs/output.log 2>&1 &
或者使用 screen:
screen -S openclaw
openclaw
# Press Ctrl+A then D to detach
或者使用 tmux:
tmux new -s openclaw
openclaw
# Press Ctrl+B then D to detach
作为 systemd 服务运行(始终在线)
创建systemd服务用于自动启动:
-
创建服务文件:
sudo nano /etc/systemd/system/openclaw.service -
添加配置:
[Unit] Description=OpenClaw Personal AI Assistant After=network.target [Service] Type=simple User=your-username WorkingDirectory=/home/your-username ExecStart=/usr/bin/openclaw Restart=always RestartSec=10 Environment="NODE_ENV=production" [Install] WantedBy=multi-user.target将
your-username替换为您的实际用户名。 -
重新加载systemd:
sudo systemctl daemon-reload -
启用服务:
sudo systemctl enable openclaw -
启动服务:
sudo systemctl start openclaw -
检查状态:
sudo systemctl status openclaw -
查看日志:
sudo journalctl -u openclaw -f
使用pm2(进程管理器)
安装pm2:
npm i -g pm2
启动 OpenClaw:
pm2 start openclaw
pm2 save
pm2 startup
pm2 startup 命令将自动生成 systemd 服务。
Raspberry Pi 特定设置
性能优化
树莓派的资源有限。优化:
-
使用更轻的AI模型:
- 本地模型(Ollama)效率更高
- 或者使用较小的云模型
-
限制并发操作:
- 配置 OpenClaw 以处理更少的并发请求
-
监控资源:
htop
始终开启设置
对于 24/7 运行的 Raspberry Pi:
- 使用systemd服务(见上文)
- 启用自动登录(如果需要)
- 配置电源管理:
sudo raspi-config # Navigate to Advanced Options → Wait for Network at Boot
Cloudflare 隧道(外部访问)
将 OpenClaw 安全地暴露在互联网上:
-
安装cloudflared:
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm64 -o cloudflared chmod +x cloudflared sudo mv cloudflared /usr/local/bin/ -
验证:
cloudflared tunnel login -
创建隧道:
cloudflared tunnel create openclaw -
配置: 创建
~/.cloudflared/config.yml:tunnel: <tunnel-id> credentials-file: /home/pi/.cloudflared/<tunnel-id>.json ingress: - hostname: openclaw.yourdomain.com service: http://localhost:3000 - service: http_status:404 -
运行隧道:
cloudflared tunnel run openclaw -
添加到systemd(用于自动启动):
sudo cloudflared service install
ARM64 支持
OpenClaw 工作在 ARM64 架构上:
- Apple Silicon Mac(通过 Linux VM)
- 树莓派 4+(64 位)
- AWS Graviton 实例
- 其他 ARM64 服务器
安装与 x86_64 相同。一行安装程序会自动检测架构。
对于 ARMv7(32 位 Raspberry Pi),某些软件包可能不可用。使用分发包或从源代码构建。
故障排除
权限被拒绝错误
如果您看到权限错误:
sudo npm i -g openclaw
或者修复 npm 权限:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
未找到命令
如果未找到 openclaw:
-
检查npm全局路径:
npm config get prefix -
添加到路径:
echo 'export PATH="$(npm config get prefix)/bin:$PATH"' >> ~/.bashrc source ~/.bashrc -
重启终端
端口已在使用中
更改端口:
openclaw --port 3001
或者找到并终止该进程:
lsof -ti:3000 | xargs kill
# or
sudo netstat -tlnp | grep :3000
sudo kill <PID>
systemd 服务问题
如果服务无法启动:
-
检查日志:
sudo journalctl -u openclaw -n 50 -
验证用户: 确保服务以正确的用户身份运行
-
检查权限:
ls -la ~/.openclaw -
手动测试:
openclaw
Raspberry Pi 特定问题
内存不足:
# Increase swap
sudo dphys-swapfile swapoff
sudo nano /etc/dphys-swapfile
# Set CONF_SWAPSIZE=2048
sudo dphys-swapfile setup
sudo dphys-swapfile swapon
性能缓慢:
- 使用更轻的AI模型
- 限制浏览器会话
- 减少内存使用
性能提示
资源监控
监控CPU和内存:
htop
# or
top
监控磁盘使用情况:
df -h
du -sh ~/.openclaw
```### 优化
- **使用本地模型**在低端硬件上获得更好的性能
- **限制浏览器会话**以减少内存使用
- **配置日志轮转**以防止磁盘填满
- **使用SSD**代替SD卡(Raspberry Pi)
## 更新 OpenClaw
更新到最新版本:
```bash
npm update -g openclaw
或者重新运行安装程序:
curl -fsSL https://openclaw.ai/install.sh | bash
卸载
删除 OpenClaw:
npm uninstall -g openclaw
删除配置:
rm -rf ~/.openclaw
停止并删除 systemd 服务:
sudo systemctl stop openclaw
sudo systemctl disable openclaw
sudo rm /etc/systemd/system/openclaw.service
sudo systemctl daemon-reload
后续步骤
现在 OpenClaw 已安装在 Linux 上:
结论
Linux 是 OpenClaw 的绝佳平台,特别是对于始终在线的部署和 Raspberry Pi 项目。一行安装程序可以处理大部分复杂性,而 systemd 集成使其可以轻松地作为服务运行。
> Related Articles
OpenClaw Linux 安装指南:在 Ubuntu、Debian、Fedora 和 Raspberry Pi 上安装
OpenClaw 的完整 Linux 安装指南。涵盖 Ubuntu、Debian、Fedora、ARM64 支持、Raspberry Pi 设置和用于始终在线访问的 Cloudflare 隧道。
OpenClaw Linux Setup Guide: Install on Ubuntu, Debian, Fedora & Raspberry Pi
Complete Linux installation guide for OpenClaw. Covers Ubuntu, Debian, Fedora, ARM64 support, Raspberry Pi setup, and Cloudflare tunnel for always-on access.
Guide d'installation d'OpenClaw Linux : installer sur Ubuntu, Debian, Fedora et Raspberry Pi
Guide d'installation Linux complet pour OpenClaw. Couvre la prise en charge d'Ubuntu, Debian, Fedora, ARM64, la configuration de Raspberry Pi et le tunnel Cloudflare pour un accès permanent.
Need help?
Join the OpenClaw community on Discord for support, tips, and shared skills.
Join Discord →