cursor 使用 gvm管理的go的环境出现 Failed to find the “go“ binary in either GOROOT() 错误

一、测试环境
  1. windows11 cursor 2.1.20版本 连接 wsl2 Ubuntu22.04,gvm 安装在linux子系统
  2. 同样的环境 vscode 正常使用gvm的go环境路径,而cursor报下面的错误

错误如下

bash 复制代码
Failed to find the "go" binary in either GOROOT() or PATH(/home/shayuer/.cursor-server/bin/a8d8905b06c8da1739af6f789efd59c28ac2a680/bin/remote-cli:/home/shayuer/.local/bin:/usr/local/cuda-12.9/bin:/run/user/1000/fnm_multishells/2918_1763875263165/bin:/home/shayuer/.local/share/fnm:/home/shayuer/miniconda3/bin:/home/shayuer/miniconda3/condabin:/home/shayuer/.cursor-server/bin/a8d8905b06c8da1739af6f789efd59c28ac2a680/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/Volta:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0:/mnt/c/WINDOWS/System32/OpenSSH:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA App/NvDLISR:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/Program Files/dotnet:/mnt/d/Programs/Git/cmd:/mnt/c/Users/amliu/AppData/Local/Volta/bin:/mnt/c/Users/amliu/.loca...

查询相关资料有说是 cursor 连接wsl2环境在开启时不会像vscode一样加载登录 .bashrcgvm 没有更改GOPATH,而全局变量中没有安装go,于是报错了

二、cursor 在 settings.json 配置 GO环境变量(更换新的go版本需要重新指定)

秉着继续使用gvm管理多个go版本,在使用cursor开发go程序时,可以使用手动在settings.json 文件中加入go的路径,后续如果使用其他go版本,在gvm install 需要的go版本后再次将cursorsettings.json文件 go路径重新指定新的即可,步骤如下:

  1. cursor 主页面下使用快捷键:ctrl + shift + p,输入 Preferences: Open User Settings (JSON) 打开 settings.json 配置文件
  2. 写入以下go配置(去掉注释,替换成自己的实际路径):
bash 复制代码
	"go.alternateTools": {
        "go": "/home/shayuer/.gvm/gos/go1.22.12/bin/go"  // 指定 go 可执行文件,使用gvm管理的路径
    },
    "go.goroot": "/home/shayuer/.gvm/gos/go1.22.12",      // 使用gvm管理的路径
    "go.gopath": "/home/shayuer/.gvm/pkgsets/go1.22.12/global"   //设置项目的 GOPATH,使用gvm管理的路径
  1. 重启 cursor,新安装的go环境IDE还会安装 gopls,需要等待一段时间,终端中会打印出gopls安装的路径,观察是否与设置的路径相同

相关路径为:

bash 复制代码
toolsGopath: 
gopath: /home/shayuer/.gvm/pkgsets/go1.22.12/global
GOROOT: /home/shayuer/.gvm/gos/go1.22.12
PATH: /home/shayuer/.gvm/gos/go1.22.12/bin:/home/shayuer/.cursor-server/bin/a8d8905b06c8da1739af6f789efd59c28ac2a680/bin/remote-cli:/home/shayuer/.local/bin:/usr/local/cuda-12.9/bin .....
三、ubuntu 使用 gvm 安装管理多个go版本

ubuntu22.04安装gvm管理go

相关推荐
Cerrda8 小时前
把团队 Mock 工作流做成可安装 Skill:faker-mock-setup 上架 skills.sh 实践
ai编程·cursor
把所有砖敲烂10 小时前
AI 工具选型:豆包、WorkBuddy、Codex 与 Hermes 实践
openai·cursor
啊哈一半醒11 小时前
Go 语言 Context 全方位详解:原理、实战与避坑
开发语言·后端·golang
名字还没想好☜13 小时前
Go 的 io.Reader/Writer 组合实战:io.Copy、TeeReader、MultiWriter 优雅处理数据流
开发语言·后端·golang·go·iphone
ttwuai16 小时前
Go 后台定时任务启停不生效怎么办?先查调度同步链路
开发语言·后端·golang
运维开发笔记16 小时前
3.1 Go if 语句学习笔记
golang
进击的程序猿~2 天前
Go Interface源码深度解析指南
开发语言·后端·golang
—Qeyser2 天前
Sponge 脚手架快速创建后端API及接口使用完整教程
golang
云卷云舒___________2 天前
视频抽奖ChatGPT Plus | Cursor迭代Composer3、Sonnet5.5或下月发布、腾讯押注WorkBuddy办公AI 8月9日 AI日报
cursor·腾讯·anthropic·vega·ai日报·composer3·sonnet55