Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

OpenCode Installation

OpenCode Installation

OpenCode is an open-source AI coding Agent that supports development tasks such as understanding code, modifying files, and executing commands in the terminal, and also provides a desktop client and a Web interface.

This section introduces how to install the terminal version.

This article is updated according to OpenCode 2 the official installation documentation. Both OpenCode 1 and 2 use the opencode command, and by default cannot be installed side by side. In older tutorials, opencode-ai was the npm package for V1; the new version uses @opencode/cli。

If you installed V1 via a package manager, first uninstall the old package with the corresponding package manager, then install V2; when installing with the new official script, the old binary at the script's install location will be replaced. Existing plugins and server-side API integrations should refer to the V1 migration guide。

Before you install

1. OS requirements

2. Terminal tools

A modern terminal with truecolor support is recommended, for example:

For more terminal tools, see:Terminal tool recommendations。

3. Model services

OpenCode comes with some free models and also supports connecting to other model services; an API Key is not required before installation. When using third-party models, you need to configure an API Key or complete account authorization as required by the provider.

Common model services include:

The availability of free models is subject to the current interface; costs for third-party models are charged by the corresponding provider.


Installation method

Choose one of the following methods. The official script and standalone binary do not require Node.js to be pre-installed; only when using a package manager such as npm do you need to prepare the corresponding environment.

1. One-click installation (macOS / Linux / WSL)

Execute the new official installation script in the terminal:

curl -fsSL https://opencode.ai/v2/install | bash

The script detects the OS and processor architecture, downloads the current release, and installs it to:

~/.opencode/bin

After installation, reopen the terminal as prompted to make the PATH configuration take effect. Then enter the project directory and start:

cd /path/to/your/project
opencode

Please replace /path/to/your/project with the actual project path.

Terminal prompt after OpenCode installation completes, illustration of the old interface

The image above shows an older installation prompt; actual commands and prompts are subject to the current version.

2. Install using npm, Bun, pnpm, or Yarn

If Node.js and npm are already installed, you can run:

npm install -g @opencode/cli

You can also choose any of the following methods:

Bun:

bun install -g --trust @opencode/cli

pnpm:

pnpm add -g --allow-build=@opencode/cli @opencode/cli

Yarn Classic:

yarn global add @opencode/cli

The new npm package needs to run a post-install script to select the native binary for the current platform. Bun's --trust and pnpm's --allow-build are used to allow the required scripts; don't omit them.

The above are installation methods for macOS, Linux, and WSL. The current V2 documentation does not support native Windows package manager installation; please use the standalone binary described later.

3、macOS / Linux(Homebrew)

Users who already have Homebrew installed can use the official tap:

brew install anomalyco/tap/opencode-v2

brew install anomalyco/tap/opencode corresponds to V1. The Homebrew core repository's brew install opencode currently also provides V2, but its update cadence may differ from the official tap.

4. Windows installation

Method 1: Install in WSL

If you want to use a Linux development environment, you can first install WSL in an administrator PowerShell:

wsl --install

Restart the system as prompted and complete Linux user initialization. Then open a WSL distribution terminal such as Ubuntu and run:

curl -fsSL https://opencode.ai/v2/install | bash

Reopen the WSL terminal, enter the project directory, and start:

cd ~/your-project
opencode

The above installation scripts are executed in WSL's Linux terminal, not in PowerShell.

Method 2: Native Windows installation

Open Official installation documentation, in the CLI download area select the standalone binary for Windows x64 or ARM64.

After downloading and extracting, open PowerShell in the directory containing the file and run:

.\opencode.exe --version

data to the child component via opencode.exe Add that directory to the user's PATH environment variable; after reopening the terminal, you can run in the project directory:

opencode

Chocolatey, Scoop, and (mentioned in older tutorials) npm install -g opencode-ai are not native Windows installation methods for V2 in this section.

5. Other Linux installation methods

Arch Linux official repository:

sudo pacman -S opencode

AUR package:

paru -S opencode-beta

If you use Mise, you can run:

mise use -g opencode

According to the current official documentation, installing V2 requires Mise 2026.10.9 or newer; earlier Mise versions install V1.

You can also download the standalone CLI binary from Official installation documentation When downloading manually, you need to match the processor architecture and the glibc / musl environment; older x64 processors can choose the baseline build.

6. Docker (optional)

OpenCode also provides Docker images. V2 uses explicit version tags; the official documentation takes 2.0.0 as an example:

docker run -it --rm ghcr.io/anomalyco/opencode:2.0.0

Here, 2.0.0 is a version tag example and does not represent the latest version. In actual use, select the published tag you need; when working with local projects, you also need to configure project directory mounting.


Verify the installation

After installation, run:

opencode --version

If it can output a version number, the command is working. This article installs V2, so the version number should be 2.x, with the specific minor version subject to actual output.

If it still shows 1.x, there may be an older version in PATH. On macOS / Linux / WSL you can check:

type -a opencode

On Windows PowerShell you can check:

Get-Command opencode -All

Check the old installation location based on the output, remove the old version using the corresponding installation method, then reopen the terminal.


Start OpenCode

In the project directory, run:

cd /path/to/your/project
opencode

You can also specify the project path directly:

opencode /path/to/your/project

After starting, a terminal interactive UI (TUI) will open:

OpenCode terminal interactive interface, illustration of the legacy interface

The image above shows an older interface; the current version's layout may differ.

Connect a model

In OpenCode's input box, run:

/connect

Select a model provider, enter the API Key or complete account authorization as prompted. Then run:

/models

Select the model to use and you can start asking questions. For example:

请介绍这个项目的目录结构,并说明如何启动。

/connect and /models are commands inside the OpenCode interface, not executed in the system terminal.


Common questions

1. Prompt says the opencode command is not found

First, reopen the terminal. If you installed with the official script and it still prompts command not found, you can first verify with the full path:

"$HOME/.opencode/bin/opencode" --version

If it outputs a version number, the main issue is that the PATH configuration hasn't taken effect. Bash / Zsh users can run in the current terminal:

export PATH="$HOME/.opencode/bin:$PATH"

To make it permanent, add this line to the config file corresponding to your current Shell ~/.bashrc or ~/.zshrc, avoiding duplicate additions. Fish users can run:

fish_add_path "$HOME/.opencode/bin"

2. EACCES or permission denied appears

First check the specific path in the full error message. It may involve the install directory, data directory, or project files; do not rely solely on EACCES the error message to modify the entire ~/.local directory's permissions.

macOS / Linux / WSL users can use the following command to check the owner of common data directories:

ls -ld "$HOME/.local" "$HOME/.local/share" "$HOME/.local/share/opencode"

Only after confirming that the error involves ~/.local/share/opencode, and that the directory is owned by root due to previous sudo usage, should you fix this directory:

sudo chown -R "$(id -u):$(id -g)" "$HOME/.local/share/opencode"

If the error path is different, check the actual path and its parent directories. For daily use, run OpenCode as a normal user; do not recursively run on the entire ~/.local directory. chmod 755。

3. View runtime paths and service status

V2 can display the data, config, cache, and log paths currently in use:

opencode debug paths

If startup is abnormal, you can check the background service status:

opencode service status

If the service is stuck, you can try restarting:

opencode service restart

Update OpenCode

In the system terminal, run:

opencode upgrade

You can also update with the original package manager. For example, V2 installed via npm:

npm install -g @opencode/cli@latest

V2 installed with the official Homebrew tap:

brew upgrade anomalyco/tap/opencode-v2

Official documentation:https://opencode.ai/v2/docs/

Official download:https://opencode.ai/download