~/content/install-opencode

Install OpenCode

Install OpenCode on macOS, Linux, Windows in minutes. Multiple methods: Homebrew, Go, Docker. Troubleshooting tips included.

last_updated: "2025-01-19"

##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:

bash
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:

bash
go install github.com/opencode-ai/opencode@latest

###Using Homebrew (macOS)

bash
brew install opencode-ai/tap/opencode

###Manual Installation

  1. Download the latest release from GitHub Releases
  2. Extract the archive
  3. Move the binary to a directory in your PATH
bash
# 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:

bash
opencode --version

You should see output similar to:

bash
OpenCode version 0.1.0

##Configuration

###Setting Up API Keys

OpenCode supports multiple AI providers. Set your API key as an environment variable:

bash
# 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"
Note

Tip: 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:

bash
# 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:

  1. Check if the binary is in your PATH
  2. Try restarting your terminal
  3. Verify the installation path

###Permission Denied

On Linux/macOS, you may need to make the binary executable:

bash
chmod +x /usr/local/bin/opencode

###API Key Issues

If you encounter API authentication errors:

  1. Verify your API key is correct
  2. Check that the environment variable is set: echo $ANTHROPIC_API_KEY
  3. 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.

Comments (Coming Soon)

Configure Giscus in environment variables to enable comments.