opencode国内安装方法

**
应用虽然不值得花太多时间,只是不一样的应用端会导致开发的进度和效果不一样,有些经验分享,目前来看codebuddy针对工作流还行,opencode+qwen3.6plus组合可以做些大项目,但同时都不要被上层应用绕进去了,运行时不要用工具。多agent是一定要做的。
这就是为何先暂停一下本地算力的芯片开发也要先搞定这个的原因。
不过随着Deepseek-v4这种大上下文的TEXT模型出来,应用的文件系统是不是可以不用那么折腾了?

在玩opencode之前,先看这个:
https://www.runoob.com/ai-agent/opencode-coding-agent.html
它里面有很多方法论和用法,同时下一步就是如何在vscode上安装opencode了。

**
问题原因
EACCES 权限不足,不要用 sudo 强行全局装 npm,容易搞坏系统环境,用下面稳妥方案。

方案1:改npm全局目录(推荐,一劳永逸)
Bash

  1. 新建用户全局目录
    mkdir -p ~/.npm-global

  2. 配置npm使用这个目录
    npm config set prefix ‘~/.npm-global’

  3. 写入环境变量
    echo ‘export PATH=~/.npm-global/bin:$PATH’ >> ~/.bashrc

  4. 生效
    source ~/.bashrc

方案2:国内镜像 + 正常安装 opencode
Bash
换阿里镜像
npm config set registry https://registry.npmmirror.com

全局安装(现在不会权限报错)
npm install -g opencode-ai

验证
Bash
opencode --version

备选极简方案(临时用)
不想改配置,直接本地安装:
Bash
npm install opencode-ai

运行
npx opencode

补充
你现在 node 版本是 v12 太老,后续AI工具大概率报错,
需要我给你一条命令一键升级到新版 Node 吗?

Vscode的Opencode插件下载地址如下:
https://marketplace.visualstudio.com/items?itemName=TanishqKancharla.opencode-vscode&ssr=false#review-details
这里下载安装,要用翻墙。

先别折腾 scoop、curl、安装脚本了,全部换掉,极简根治。

你现在核心真相

  1. 你之前敲 opencode --version 能出 1.14.22
  2. 但根本没有 C:\Users\jzlai.opencode 文件夹
  3. = 你之前的 opencode 是临时解压运行,没装到本地
  4. VSCode 插件找不到实体程序 → spawn opencode ENOENT

方案:不用任何脚本、不用curl、不用scoop

  1. 直接手动下载 OpenCode 绿色版
    浏览器打开:
    https://opencode.ai/download

下载 Windows 独立版 / Portable

解压到随便一个固定目录,比如:
Plain Text
C:\Tools\opencode
里面必有:
opencode.exe

  1. 手动永久加 PATH(一步到位)
    Win + R 输入:
    Plain Text
    sysdm.cpl
    • 高级 → 环境变量
    • 用户变量 → 找到 Path → 编辑
    • 新建,粘贴:
    Plain Text
    C:\Tools\opencode
    一路确定关闭。

  2. 新开 PowerShell 测试
    PowerShell
    opencode --version
    where opencode
    现在必须能查到路径。

  3. 最后改你 VSCode settings.json(复制全覆盖)
    JSON
    {
    “python.defaultInterpreterPath”: “c:\python314\python.exe”,
    “editor.fontSize”: 16,
    “editor.fontWeight”: “normal”,
    “editor.smoothScrolling”: true,
    “editor.formatOnType”: true,
    “window.autoDetectColorScheme”: false,
    “editor.formatOnSave”: true,
    “editor.formatOnPaste”: true,
    “statusBar.debuggingForeground”: “#FFCC00”,
    “workbench.editor.tabSizing”: “shrink”,
    “editor.minimap.enabled”: true,
    “workbench.startupEditor”: “newUntitledFile”,
    “workbench.iconTheme”: “vscode-icons”,
    “editor.fontLigatures”: true,
    “window.zoomLevel”: 0,
    “window.titleBarStyle”: “custom”,
    “editor.cursorBlinking”: “smooth”,
    “editor.tokenColorCustomizations”: {
    “functions”: “#DCDCAA”,
    “keywords”: “#C586C0”,
    “numbers”: “#B5CEA8”,
    “strings”: “#CE9178”,
    “variables”: “#9CDCFE”,
    “comments”: “#6A9955”
    },
    “editor.guides.bracketPairs”: true,
    “explorer.decorations.colors”: true,
    “workbench.editor.highlightModifiedTabs”: true,
    “editor.semanticHighlighting.enabled”: true,
    “editor.renderLineHighlight”: “all”,
    “statusBar.visible”: true,
    “breadcrumbs.enabled”: true,
    “editor.bracketPairColorization.enabled”: true,
    “editor.fontFamily”: “‘Cascadia Code’, ‘Fira Code’, ‘JetBrains Mono’, Consolas, ‘Courier New’, monospace”,
    “idf.hasWalkthroughBeenShown”: true,
    “idf.pythonInstallPath”: “C:\Users\jzlai\.espressif\tools\idf-python\3.11.2\python.exe”,
    “idf.gitPathWin”: “C:\Users\jzlai\.espressif\tools\idf-git\2.39.2\cmd\git.exe”,
    “idf.espIdfPathWin”: “C:\Users\jzlai\esp\v5.5.2\esp-idf”,
    “idf.toolsPathWin”: “C:\Users\jzlai\.espressif”,
    “claudeCode.preferredLocation”: “panel”,
    “remote.SSH.remotePlatform”: {
    “kosmo-vm”: “linux”
    },
    “opencode.cliPath”: “C:\Tools\opencode\opencode.exe”
    }

  4. 收尾

  5. 完全关闭 VSCode(全部窗口)

  6. 重新打开

  7. 打开你那个 TanishqKancharla.opencode-vscode 插件
    ✅ 直接解决 spawn opencode ENOENT
    ✅ 不会一直加载转圈

404 说明官方卸载脚本链接失效了,我们改用手动清理+官方推荐的Windows安装方案,一步到位解决问题。

一、先彻底清理残留(关键)

  1. 手动删除所有opencode相关目录(管理员PowerShell)
    PowerShell
    清理用户目录残留
    Remove-Item -Path “env:USERPROFILEo˙pencode"−Recurse−Force−ErrorActionSilentlyContinue清理npm全局安装残留(如果之前用npm装过)Remove−Item−Path"env:USERPROFILE\.opencode" -Recurse -Force -ErrorAction SilentlyContinue 清理npm全局安装残留(如果之前用npm装过) Remove-Item -Path "env:USERPROFILEo˙pencode"−Recurse−Force−ErrorActionSilentlyContinue清理npm全局安装残留(如果之前用npm装过)Remove−Item−Path"env:APPDATA\npm\node_modules\opencode-ai” -Recurse -Force -ErrorAction SilentlyContinue
    Remove-Item -Path “KaTeX parse error: Undefined control sequence: \npm at position 12: env:APPDATA\̲n̲p̲m̲\opencode*" -Fo…env:LOCALAPPDATA\opencode” -Recurse -Force -ErrorAction SilentlyContinue
    Remove-Item -Path “$env:APPDATA\opencode” -Recurse -Force -ErrorAction SilentlyContinue

  2. 清理系统PATH里的opencode路径
    PowerShell
    查看当前PATH,确认无opencode相关路径
    KaTeX parse error: Expected 'EOF', got '#' at position 10: env:PATH #̲若有,用以下命令移除(替换成你…env:PATH -replace ‘C:\Users\jzlai\.opencode\bin’, ‘’), “User”)

二、Windows官方推荐安装(2选1,优先方案1)----我目前用这个。

方案1:Scoop安装(最稳定,推荐)

  1. 安装Scoop(普通用户PowerShell,非管理员)
    PowerShell
    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
    irm get.scoop.sh | iex
  2. 安装opencode
    PowerShell
    scoop install opencode
  3. 验证安装
    PowerShell
    opencode --version
    where.exe opencode

方案2:npm全局安装(有Node.js环境用)
PowerShell
npm install -g opencode-ai

验证

opencode --version

方案3:桌面版安装(纯图形化,适合新手)
访问官方下载页:https://opencode.ai/download ,下载Windows (x64) 桌面版安装包,双击安装即可。

三、安装后配置VSCode(解决插件找不到问题)

  1. 打开VSCode设置(Ctrl+,),搜索terminal.integrated.env.windows,编辑settings.json:
    JSON
    {
    “terminal.integrated.env.windows”: {
    “PATH”: “env:USERPROFILEscoopshims;{env:USERPROFILE}\\scoop\\shims;env:USERPROFILEscoopshims;{env:PATH}” // Scoop安装用此路径
    // npm安装用:“PATH”: “env:APPDATAnpm;{env:APPDATA}\\npm;env:APPDATAnpm;{env:PATH}”
    },
    “opencode.cliPath”: “opencode” // 直接用命令名,无需绝对路径
    }
  2. 重启VSCode,重新加载TanishqKancharla.opencode-vscode插件,即可正常调用。

四、最终验证

PowerShell
终端验证
opencode --version
where.exe opencode
VSCode内打开终端,执行
opencode
✅ 出现版本号、能正常启动opencode,即安装成功。

安装好了,可以开心代码了。

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐