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

相关推荐
2601_9620702320 小时前
差异基因富集分析(R语言——GO&KEGG&GSEA)
开发语言·golang·r语言
「、皓子~21 小时前
海狸IM 2.1 正式发布
flutter·微服务·golang·electron·开源软件·im·海狸im
运维开发笔记1 天前
8.1 Go Struct 结构体基础
golang
ttwuai1 天前
Go 后台接入 CAS 单点登录后,原来的权限怎么继续生效?
开发语言·后端·golang
蓝宝石的傻话2 天前
因为MiBeeNVR,决定接 onvif-go 自己管理并重构
数码相机·重构·golang
ERD Online2 天前
Cursor 连上 MCP:读一张 ER 图,提交一版建议
数据库·后端·开源·cursor·mcp
Patrick_Wilson2 天前
Superpowers 与 Codex Harness:冲突分析与治理提示词
agent·ai编程·cursor
ttwuai2 天前
Go 后台管理系统组件库文档怎么写,才不会坑后续维护?
开发语言·javascript·golang
2601_962066232 天前
golang超详细基础入门教程_golang教程
前端·python·golang