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

相关推荐
席万里4 小时前
Go开源库gcurl实际生产级应用
开发语言·后端·golang
飞哥数智坊6 小时前
Cursor 2.1 发布实测:计划能点了,审查能用了,CR 花多少?我也替你试了
人工智能·ai编程·cursor
ChineHe8 小时前
Golang并发编程篇002_Go并发基础
开发语言·后端·golang
麻辣兔变形记1 天前
基于 Go‑Zero 的用户 CRUD Demo:如何一步步从 MySQL + sqlx 演进为 PostgreSQL + GORM + 微服务架构
mysql·微服务·postgresql·架构·golang
i***27951 天前
【golang学习之旅】使用VScode安装配置Go开发环境
vscode·学习·golang
yaocheng的ai分身2 天前
Cursor 2.1 版本更新日志
cursor
le serein —f2 天前
用go实现-反转链表
leetcode·链表·golang
席万里2 天前
关于Go的init函数执行顺序#黑魔法
开发语言·网络·golang
喵了几个咪2 天前
Golang微服务框架kratos实现Socket.IO服务
开发语言·微服务·golang