I am using Ubuntu 20.04.3 LTS, VSCode 1.62.3, go 1.17.3 linux/amd64
When I start the debugger in VSCode it shows me this warning
The "dlv-dap" command is not available. Please select "install", or follow the installation instructions here. Source: Go (Extension) [Install] [Install All]
I click Install and see that in the output:
Tools environment: GOPATH=/home/raspberry/GolandProjects
Installing 1 tool at /home/raspberry/GolandProjects/bin in module mode.
dlv-dap
Installing github.com/go-delve/delve/cmd/dlv@master FAILED
{
"killed": false,
"code": 2,
"signal": null,
"cmd": "/usr/local/go/bin/go get -x -d github.com/go-delve/delve/cmd/dlv@master",
"stdout": "",
"stderr": "go: cannot find GOROOT directory: /snap/bin/go\n"
}
1 tools failed to install.
dlv-dap: failed to install dlv-dap(github.com/go-delve/delve/cmd/dlv@master): Error: Command failed: /usr/local/go/bin/go get -x -d github.com/go-delve/delve/cmd/dlv@master
go: cannot find GOROOT directory: /snap/bin/go
When I check GOROOT by the go tool I see that:
$ go env GOROOT
/usr/local/go
When I check /snap/bin/ I see that:
~$ cd /snap/bin/
:/snap/bin$ ls
canonical-livepatch pre-commit.validate-config
go pre-commit.validate-manifest
gofmt snap-store
go.gofmt snap-store.ubuntu-software
pre-commit snap-store.ubuntu-software-local-file
I'm confused, there is /snap/bin/go but VSCode tells me that there is not and fails to run the debugger. How to fix it?
UPDATE 1
When I set GOROOT to /snap/bin/go by typing this into the console:
$ export GOROOT=/snap/bin/go
VSCode starts to print that when I try to run the debugger:
Couldn't find dlv-dap at the Go tools path, /home/raspberry/GolandProjects/, /home/raspberry/GolandProjects or /usr/local/go/bin:/home/raspberry/.local/bin:/home/raspberry/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Follow the setup instruction in https://github.com/golang/vscode-go/blob/master/docs/debugging.md#getting-started.
So, here is the fix - add to VSCode Preferences: Open Settings (JSON)
this line
"go.goroot": "/snap/go/current"
Here is the explanation - https://github.com/golang/vscode-go/issues/166
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.