在WSL中安装OpenCode教程

什么是WSL

安装WSL

前置条件

  • 确保硬件虚拟化(VT-x / AMD‑V)已启用,打开任务管理器,点【性能】→【CPU】

  image

  •  搜索栏输入“启用或关闭windows功能”,勾选【适用于Linux的windows子系统】和【虚拟机平台】

  image

 

安装 WSL 命令

  • 右键单击并选择“以 管理员 身份运行”,在管理员模式下打开 PowerShell,输入 wsl --install 命令,然后重新启动计算机
wsl --install
  •  如果执行上述指令后出现以下内容,先执行一次

image

开启【适用于 Linux 的 Windows 子系统】

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

开启【虚拟机平台】(WSL2 必需)

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

更新wsl版本

wsl --update

然后重启电脑

  • 安装下载完成又提示新的错误

  image

  按提示执行了,然后重启电脑

wsl.exe --install --no-distribution
  • 安装成功

  image

  • 查看版本

  image

 

 安装opencode

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

安装完成执行一次,就可以运行opencode了

exec $SHELL

image

image

posted on 2026-10-29 16:43  Cynthia_W  阅读(20)  评论(0)    收藏  举报