> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/opencode-ai/opencode/llms.txt
> Use this file to discover all available pages before exploring further.

# Installation

> Install OpenCode using the install script, Homebrew, AUR, or build from source with Go.

OpenCode is distributed as pre-built binaries for macOS, Linux, and Windows. Choose your preferred installation method below.

## Prerequisites

OpenCode requires Go 1.24.0 or higher if building from source. For binary installations, no prerequisites are needed.

## Install script (recommended)

The install script is the fastest way to get started with OpenCode. It automatically downloads the latest version for your platform and adds it to your PATH.

<CodeGroup>
  ```bash Install latest version theme={null}
  curl -fsSL https://raw.githubusercontent.com/opencode-ai/opencode/refs/heads/main/install | bash
  ```

  ```bash Install specific version theme={null}
  curl -fsSL https://raw.githubusercontent.com/opencode-ai/opencode/refs/heads/main/install | VERSION=0.1.0 bash
  ```
</CodeGroup>

The script will:

1. Detect your OS and architecture (linux/mac, x86\_64/arm64)
2. Download the appropriate binary to `~/.opencode/bin`
3. Add `~/.opencode/bin` to your PATH in your shell config file
4. Display installation success message

<Note>
  After installation, restart your shell or run `source ~/.bashrc` (or equivalent) to use OpenCode immediately.
</Note>

## Homebrew (macOS and Linux)

If you use Homebrew, you can install OpenCode from our tap:

```bash theme={null}
brew install opencode-ai/tap/opencode
```

To upgrade to the latest version:

```bash theme={null}
brew upgrade opencode
```

## AUR (Arch Linux)

Arch Linux users can install OpenCode from the Arch User Repository using their preferred AUR helper:

<CodeGroup>
  ```bash Using yay theme={null}
  yay -S opencode-ai-bin
  ```

  ```bash Using paru theme={null}
  paru -S opencode-ai-bin
  ```
</CodeGroup>

## Go install

If you have Go 1.24.0 or higher installed, you can install OpenCode directly:

```bash theme={null}
go install github.com/opencode-ai/opencode@latest
```

<Warning>
  Make sure `$GOPATH/bin` (usually `~/go/bin`) is in your PATH.
</Warning>

## Build from source

For development or if you want the latest unreleased features:

<Steps>
  <Step title="Clone the repository">
    ```bash theme={null}
    git clone https://github.com/opencode-ai/opencode.git
    cd opencode
    ```
  </Step>

  <Step title="Build the binary">
    ```bash theme={null}
    go build -o opencode
    ```
  </Step>

  <Step title="Run OpenCode">
    ```bash theme={null}
    ./opencode
    ```

    Optionally, move the binary to a directory in your PATH:

    ```bash theme={null}
    sudo mv opencode /usr/local/bin/
    ```
  </Step>
</Steps>

## Verify installation

After installation, verify that OpenCode is available:

```bash theme={null}
opencode --version
```

You should see the version number printed to the console.

## Setup API keys

Before using OpenCode, you need to configure at least one AI provider. OpenCode supports multiple providers and will automatically detect which one to use based on available API keys.

<Info>
  OpenCode checks providers in this order: GitHub Copilot → Anthropic → OpenAI → Gemini → Groq → OpenRouter → AWS Bedrock → Azure OpenAI → VertexAI
</Info>

### Set environment variables

The simplest way to configure providers is through environment variables:

<CodeGroup>
  ```bash Anthropic Claude theme={null}
  export ANTHROPIC_API_KEY="sk-ant-..."
  ```

  ```bash OpenAI theme={null}
  export OPENAI_API_KEY="sk-..."
  ```

  ```bash Google Gemini theme={null}
  export GEMINI_API_KEY="..."
  ```

  ```bash GitHub Copilot theme={null}
  export GITHUB_TOKEN="ghp_..."
  ```

  ```bash Groq theme={null}
  export GROQ_API_KEY="..."
  ```

  ```bash OpenRouter theme={null}
  export OPENROUTER_API_KEY="..."
  ```

  ```bash Azure OpenAI theme={null}
  export AZURE_OPENAI_ENDPOINT="https://..."
  export AZURE_OPENAI_API_KEY="..."
  export AZURE_OPENAI_API_VERSION="2024-02-15-preview"
  ```

  ```bash AWS Bedrock theme={null}
  export AWS_ACCESS_KEY_ID="..."
  export AWS_SECRET_ACCESS_KEY="..."
  export AWS_REGION="us-east-1"
  ```

  ```bash VertexAI theme={null}
  export VERTEXAI_PROJECT="your-project-id"
  export VERTEXAI_LOCATION="us-central1"
  ```
</CodeGroup>

<Tip>
  Add these exports to your shell configuration file (`~/.bashrc`, `~/.zshrc`, etc.) to make them permanent.
</Tip>

### Configuration file

For more control, create a configuration file at `~/.opencode.json` or `~/.config/opencode/.opencode.json`:

```json theme={null}
{
  "providers": {
    "anthropic": {
      "apiKey": "sk-ant-...",
      "disabled": false
    },
    "openai": {
      "apiKey": "sk-...",
      "disabled": false
    },
    "gemini": {
      "apiKey": "...",
      "disabled": false
    }
  },
  "agents": {
    "coder": {
      "model": "claude-4-sonnet",
      "maxTokens": 5000
    }
  }
}
```

## Next steps

<CardGroup cols={2}>
  <Card title="Quickstart guide" icon="rocket" href="/quickstart">
    Run your first AI assistant session
  </Card>

  <Card title="Configuration" icon="gear" href="/configuration">
    Learn about all configuration options
  </Card>
</CardGroup>
