##Prerequisites
Before installing OpenCode, make sure you have:
- Operating System: macOS, Linux, or Windows (WSL2)
- Terminal: A modern terminal emulator
- API Key: An API key from your preferred AI provider (Anthropic, OpenAI, etc.)
##Installation Methods
###Quick Install (Recommended)
The fastest way to install OpenCode is using our install script:
curl -fsSL https://opencode.ai/install.sh | sh
This script automatically detects your system and installs the appropriate binary.
###Using Go
If you have Go installed (version 1.21+), you can install directly:
go install github.com/opencode-ai/opencode@latest
###Using Homebrew (macOS)
brew install opencode-ai/tap/opencode
###Manual Installation
- Download the latest release from GitHub Releases
- Extract the archive
- Move the binary to a directory in your PATH
# Example for Linux/macOS
tar -xzf opencode_linux_amd64.tar.gz
sudo mv opencode /usr/local/bin/
##Verify Installation
After installation, verify that OpenCode is properly installed:
opencode --version
You should see output similar to:
OpenCode version 0.1.0
##Configuration
###Setting Up API Keys
OpenCode supports multiple AI providers. Set your API key as an environment variable:
# For Anthropic Claude
export ANTHROPIC_API_KEY="your-api-key-here"
# For OpenAI
export OPENAI_API_KEY="your-api-key-here"
# For Google Gemini
export GOOGLE_API_KEY="your-api-key-here"
NoteTip: Add these exports to your shell profile (
~/.bashrc,~/.zshrc, etc.) to make them permanent.
###Configuration File
OpenCode also supports a configuration file at ~/.config/opencode/config.yaml:
# Default model to use
model: claude-3-5-sonnet
# API provider settings
providers:
anthropic:
api_key: ${ANTHROPIC_API_KEY}
openai:
api_key: ${OPENAI_API_KEY}
# Editor settings
editor:
theme: terminal
tab_size: 2
##Troubleshooting
###Command Not Found
If you get "command not found" after installation:
- Check if the binary is in your PATH
- Try restarting your terminal
- Verify the installation path
###Permission Denied
On Linux/macOS, you may need to make the binary executable:
chmod +x /usr/local/bin/opencode
###API Key Issues
If you encounter API authentication errors:
- Verify your API key is correct
- Check that the environment variable is set:
echo $ANTHROPIC_API_KEY - Ensure your API key has the necessary permissions
##Next Steps
Now that you have OpenCode installed, head to the Getting Started guide to learn how to use it effectively.