Install OpenCode on Linux: version 1 or 2, sign-in, updates
OpenCode's two install lines give two different versions. Install it on Ubuntu or a server, connect a provider with no browser, then update, pin or remove it.
OpenCode has two live versions, and its two install lines give you different ones. curl -fsSL https://opencode.ai/v2/install | bash, the line on OpenCode’s home page, installs version 2 (2.1.3 on October 22, 2026). curl -fsSL https://opencode.ai/install | bash, the line in the version 1 docs, installs version 1 (1.19.4 that day). Either puts one binary at ~/.opencode/bin/opencode and adds that folder to PATH at the end of ~/.bashrc. On a server, connect a model provider by pasting an API key or setting it in the environment. If you are on version 1, opencode upgrade --major moves you to 2.
Two versions, two install lines
Both versions use the command opencode, and OpenCode’s migration page says they “are no longer installed side by side by default”. So the first thing to know is which one a given line gives you. As of October 22, 2026:
| Version 1 | Version 2 | |
|---|---|---|
Install address | opencode.ai/install | opencode.ai/v2/install |
Where its install line is printed | The version 1 docs | OpenCode’s home page and the version 2 docs |
npm package | opencode-ai | @opencode/cli |
Newest that day | 1.19.4 | 2.1.3 |
opencode --version prints, on October 11’s releases | 1.19.0 | opencode v2.0.26 |
Docs | opencode.ai/docs | opencode.ai/v2/docs |
The shorter address is the older version: on that day https://opencode.ai/install redirected to the install script on the repository’s v1 branch. Version 2 is not a routine upgrade. The migration page lists three deliberate breaks: plugins use a new plugin API, the server API and its clients have new contracts, and the terminal client’s configuration moves. A tutorial or a plugin written before version 2 may assume version 1, so check which one it means before copying an install line from it.
Install it
curl -fsSL https://opencode.ai/v2/install | bashCopiedOn an Ubuntu 24.04 server with Ubuntu’s stock shell files, as of October 11, 2026, this takes a few seconds. It prints Installing opencode version: 2.0.26 and Successfully added opencode to $PATH in /home/you/.bashrc, and leaves a single 210 MB executable at ~/.opencode/bin/opencode, with a two-line script named opencode2 beside it that runs the same binary. The line it appends to ~/.bashrc:
# opencode
export PATH=/home/you/.opencode/bin:$PATHCopiedOpen a new terminal, or run source ~/.bashrc, and opencode --version answers. The script takes three options after bash -s --: --version <version> installs a specific release, --no-modify-path leaves your shell files alone, and --binary <path> installs a binary you already have. It needs curl and tar, and it chooses the build for you: the musl one on Alpine, and a baseline one on an x64 processor without AVX2.
The other routes in the version 2 docs are npm install -g @opencode/cli and brew install anomalyco/tap/opencode-v2. The npm package “uses a postinstall script to select the native opencode binary for your platform”, so an npm set up to skip install scripts will not produce a working command.
Where the PATH line does not reach
Ubuntu’s stock ~/.bashrc opens with a check that returns at once in any shell that is not interactive, and the installer’s line sits at the bottom of the file, below it. So an interactive shell finds opencode, and neither a login shell running a command nor a plain one does:
$ bash -ic 'command -v opencode'
/home/you/.opencode/bin/opencode
$ bash -lc 'command -v opencode'
$ bash -c 'command -v opencode'
$CopiedThat is the case for ssh server 'opencode …', cron jobs and systemd services. Give them the full path, ~/.opencode/bin/opencode.
Already on version 1
Version 1 can move itself. From 1.19.0, installed with the version 1 line:
$ opencode upgrade --major
● Using method: curl
● From 1.19.0 → OpenCode 2
└ Done
$ opencode --version
opencode v2.0.26CopiedIt takes a few seconds and replaces the binary in place. The 1.19.0 release note is where the command appeared, and the same note changes how version 1 updates: “Use /update to install OpenCode updates or upgrade to OpenCode 2; updates are no longer installed automatically.” If you installed version 1 through a package manager, the migration page asks you to remove it before installing version 2. Staying on version 1 now costs something: in a pinned issue of October 26, 2026, OpenCode’s maintainers write that “v1 no longer supports free models and only gets fixes for critical bugs,” while the shorter install address still gives version 1. A free model refused on version 1 is the “free tier can only be used from within OpenCode” message.
Connect a provider with no browser
OpenCode needs a model to talk to, and on a server the dependable way to give it one is a key. In version 2:
opencode auth login # pick a provider from a list
opencode auth login anthropic --method key # straight to pasting a key
opencode auth list # what is connectedCopiedThe providers page sets one limit that matters for automation: “API-key entry and provider forms require an interactive terminal.” An SSH session is one; a script is not. For a script or a service, put the key in the environment instead. OpenCode reads a provider’s variable without saving it:
# one run, with its own private server
ANTHROPIC_API_KEY=sk-ant-... opencode --standalone
# the background service every later command uses
opencode service set env ANTHROPIC_API_KEY sk-ant-...CopiedSign-ins that go through a browser are less certain on a machine without one. A provider’s OAuth method gives “a browser URL, device code, or authorization-code prompt”, and a device code works from anywhere because you type it into a browser on another device. Before version 2.0.32, though, an issue reported that on a Linux machine without xdg-open, opencode auth login printed the authorization link and then exited with Error: Executable not found in $PATH: "xdg-open", so the sign-in could not be finished. OpenCode fixed it in 2.0.32 (October 16, 2026), and from there the sign-in prints its link and carries on. On Ubuntu that command comes from the xdg-utils package, and the key route does not use it.
Saved keys and tokens are on the disk in plain reach of your user account: version 2 keeps them in its database, normally ~/.local/share/opencode/opencode.db, and version 1 in ~/.local/share/opencode/auth.json. Treat both like a password file. OpenCode’s pricing covers which plans and keys it takes and what its own free and paid models cost.
The background service, and two installs on one server
Version 2 does its work in a background server it calls the service, which the first command starts and later commands reuse. Even opencode auth list starts it, and opencode service status then prints its address, a port on 127.0.0.1. opencode service stop stops it, and --standalone runs a command with a private server of its own.
Two installs on one machine want the same service port. With another OpenCode 2 service already running under a different home folder, the first command from a new install fails with:
Error: Managed service port 49374 on 127.0.0.1 is already in use by another
process. Configure another port with `opencode service set port <port>` and
start the service again.CopiedDoing what it says clears it:
opencode service set port 49391
opencode service statusCopiedA second install is not the only thing that holds the port. Another Linux account’s OpenCode service can, and so can an outgoing connection: 49374 sits inside Linux’s default range for the local ports of outgoing connections (32768 to 60999), so the system can hand it to any program for a moment, and the service then reports it in use with nothing listening on it. That last case is issue #62891, open and reproduced as of November 14, 2026. ss -tanp | grep 49374 shows what has it. Setting another port, as above, clears the first two; for the third, choose a port outside that range, since 49391 is inside it too. OpenCode’s background service goes further: every opencode service setting, what a reboot does, and how to read “Server process exited with code 1”.
The service is also what serves OpenCode’s web interface. OpenCode on a remote server covers reaching that from a laptop or a phone, and what protects it.
Updates, pinning and removal
In version 2 updating is a setting in the global config, ~/.config/opencode/opencode.json. The config page gives its three values: "disable" skips update checks, "notify" shows an update before installing it and is the default, and "auto" installs without asking. It adds that an automatic install “does not restart a running server”, so on a machine where the service runs for days, restart it to pick the update up.
opencode upgrade # to the newest
opencode upgrade 2.0.21 # to one version
curl -fsSL https://opencode.ai/v2/install | bash -s -- --version 2.0.21CopiedTo hold a version, install it by number and set "update": "disable".
Removal differs between the versions, and opencode uninstall --dry-run shows which you have before anything is deleted. Version 1’s dry run lists everything: its data, cache, config and state folders, the binary and the PATH line in ~/.bashrc, with --keep-config and --keep-data to spare some. Version 2 (2.0.26 to 2.1.3) describes its own as “Uninstall OpenCode, keeping session data, configuration, and state”, and its dry run lists only the cache, stopping the background service, and the binary marked for manual removal. To erase a version 2 install completely, delete these yourself afterwards:
~/.opencode # the binary
~/.config/opencode # configuration
~/.local/share/opencode # sessions, the database with saved keys, logs
~/.local/state/opencode # service state
~/.cache/opencodeCopiedopencode debug paths prints the same list for your machine, which is the one to trust if you have set any of the XDG variables.
When it does not work
opencode: command not foundfrom a script, cron orssh server '…'. The PATH line is below the interactive check in~/.bashrc. Use~/.opencode/bin/opencode.Managed service port … is already in use by another process. Another OpenCode 2 service on the machine has the port:opencode service set port <port>.Executable not found in $PATH: "xdg-open"during sign-in. The issue above, on a version 2 older than 2.0.32. Update, or connect with a key.- A service that stops answering. OpenCode’s troubleshooting page starts with
opencode service status, restarts a stuck service withopencode service restart, and warns against deleting or editing the service files or the database by hand. - Anything else. The log is
~/.local/share/opencode/log/opencode.log;tail -fit while you reproduce the problem.
An interactive session ends when your SSH connection does, like any terminal program. Start it inside tmux and it stays on the server while you are away.