Bun 安装

使用 Bun 快速安装和运行 ClawdBot

概述

Bun 是一个快速的 JavaScript 运行时,可以作为 Node.js 的替代品。 使用 Bun 安装和运行 ClawdBot 可以获得更快的启动速度和更好的性能。

极速安装

比 npm 快 25 倍的安装速度

快速启动

更快的冷启动时间

兼容性

完全兼容 Node.js 生态

安装 Bun

首先需要安装 Bun 运行时:

macOS / Linux

# 使用官方脚本安装
curl -fsSL https://bun.sh/install | bash

# 重新加载 shell 配置
source ~/.bashrc  # 或 ~/.zshrc

Windows

# 使用 PowerShell
powershell -c "irm bun.sh/install.ps1 | iex"

验证安装

bun --version
# 输出: 1.0.x

安装 ClawdBot

全局安装

# 使用 Bun 全局安装
bun install -g clawdbot

# 验证安装
clawdbot --version

项目内安装

# 创建项目目录
mkdir my-clawdbot && cd my-clawdbot

# 初始化项目
bun init

# 安装 ClawdBot
bun add clawdbot

从源码安装

# 克隆仓库
git clone https://github.com/clawdbot/clawdbot.git
cd clawdbot

# 使用 Bun 安装依赖
bun install

# 构建
bun run build

# 链接到全局
bun link

运行

使用 Bun 运行

# 如果全局安装
clawdbot gateway

# 如果使用项目内安装
bun run clawdbot gateway

# 或直接使用 bunx
bunx clawdbot gateway

开发模式

# 热重载开发
bun --watch run clawdbot gateway

配置 package.json

{
  "name": "my-clawdbot",
  "scripts": {
    "start": "clawdbot gateway",
    "dev": "bun --watch run clawdbot gateway",
    "doctor": "clawdbot doctor"
  },
  "dependencies": {
    "clawdbot": "^1.3.0"
  }
}

性能优势

安装速度对比

包管理器安装时间相对速度
bun~2s25x 更快
pnpm~15s3x 更快
npm~50s基准

启动时间对比

运行时冷启动热启动
Bun~50ms~10ms
Node.js~200ms~50ms

💡 提示

Bun 使用 JavaScriptCore 引擎(Safari 的 JS 引擎),在某些场景下比 V8 更快。 ClawdBot 完全兼容 Bun 运行时。