Skip to content

1.2 安装 OpenCode

本节将介绍如何在不同的操作系统上安装 OpenCode。整个安装过程大约需要 5 分钟。

系统要求

  • 操作系统: Windows 10/11, macOS 10.15+, Linux (Ubuntu 20.04+)
  • 内存: 最少 4GB RAM(推荐 8GB+)
  • 存储: 至少 100MB 可用空间
  • 网络: 能够访问互联网

安装方式

🍎 macOS

使用 Homebrew 安装(推荐):

bash
# 1. 安装 Homebrew(如果尚未安装)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# 2. 添加 OpenCode Tap
brew tap opencode/tap

# 3. 安装 OpenCode
brew install opencode

使用 Cargo 安装:

bash
# 确保已安装 Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# 安装 OpenCode
cargo install opencode

🐧 Linux

使用 APT(Ubuntu/Debian):

bash
# 1. 添加 GPG 密钥
wget -qO- https://packages.opencode.dev/opencode.gpg | sudo# 2. apt-key add -

 添加软件源
echo "deb https://packages.opencode.dev /" | sudo tee /etc/apt/sources.list.d/opencode.list

# 3. 更新并安装
sudo apt update && sudo apt install opencode

使用 Cargo:

bash
cargo install opencode

🪟 Windows

使用 Scoop(推荐):

bash
# 1. 安装 Scoop(如果尚未安装)
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
irm get.scoop.sh | iex

# 2. 安装 OpenCode
scoop install opencode

使用 Winget:

bash
winget install OpenCode.OpenCode

验证安装

安装完成后,打开终端并运行:

bash
opencode --version

如果显示版本号(如 OpenCode v1.0.0),说明安装成功。

首次启动

bash
opencode

首次启动会:

  1. 创建配置文件目录 (~/.config/opencode/)
  2. 初始化默认配置
  3. 提示你连接 AI 模型

安装问题?

如果遇到安装问题,请查看:

下一步

安装完成后,接下来配置网络连接:

1.3 网络配置 →