OpenCode V2安装教程:Homebrew 官方源与清华镜像源(国内加速)

opencode是一款开源的AI编程工具,跑在终端里,支持OpenAI、Anthropic、Gemini等主流模型,有TUI界面也可以当命令行工具用。项目在github.com/anomalyco/opencode,官方文档在opencode.ai/v2/docs,官网是opencode.ai。
安装Homebrew
没装Homebrew的话先装:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"官方源安装
opencode官方维护了一个Homebrew tap,版本更新最快:
brew install anomalyco/tap/opencode-v2更想用Homebrew官方仓库里的版本(更新慢一些但更稳定)的话,直接:
brew install opencode用npm装也可以:
npm install -g @opencode/cli国内源安装(清华镜像)
国内从GitHub拉东西慢,可以用清华的镜像,官方说明在mirrors.tuna.tsinghua.edu.cn/help/homebrew/。
还没装Homebrew的,先设好环境变量再跑官方脚本,brew本体和homebrew-core都会从清华镜像克隆:
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"已经装好Homebrew的,把API和bottle域名换成清华镜像:
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"想长期生效就把这两个export写进~/.zshrc(或~/.bash_profile),然后brew update验证。
清华镜像同步了homebrew-core里opencode的formula和bottle,直接装官方版本就行:
brew install opencode注意anomalyco/tap/opencode-v2是第三方tap,镜像不代理它的二进制包,装了还是要从opencode.ai拉,国内建议用brew install opencode。
验证和首次使用
opencode --version在项目目录里运行:
cd 你的项目目录
opencode在界面里执行/connect,选一个提供商登录并填API Key就能用了。详细用法看官方文档。
总结
opencode安装很简单,brew或npm二选一。国内用户建议配合清华镜像用brew install opencode,速度快很多。
版权声明:
作者:xinbao
链接:https://ixinb.com/everything/opencode-%e5%ae%89%e8%a3%85%e6%95%99%e7%a8%8b%ef%bc%9ahomebrew-%e5%ae%98%e6%96%b9%e6%ba%90%e4%b8%8e%e6%b8%85%e5%8d%8e%e9%95%9c%e5%83%8f%e6%ba%90%ef%bc%88%e5%9b%bd%e5%86%85%e5%8a%a0%e9%80%9f%ef%bc%89/
文章版权归作者所有,未经允许请勿转载。
THE END