无法在Visual Studio代码中安装Go扩展

时间:2018-04-24 03:09:55

标签: go visual-studio-code

当我尝试在Visual Studio代码中安装Go扩展时,我收到如下错误消息。 我在这里错过了什么吗?

 gocode
  gopkgs
  go-outline
  go-symbols
  guru
  gorename
  godef
  goreturns
  golint
  dlv

Installing github.com/nsf/gocode FAILED
Installing github.com/uudashr/gopkgs/cmd/gopkgs FAILED
Installing github.com/ramya-rao-a/go-outline FAILED
Installing github.com/acroca/go-symbols FAILED
Installing golang.org/x/tools/cmd/guru FAILED
Installing golang.org/x/tools/cmd/gorename FAILED
Installing github.com/rogpeppe/godef FAILED
Installing github.com/sqs/goreturns FAILED
Installing github.com/golang/lint/golint FAILED
Installing github.com/derekparker/delve/cmd/dlv FAILED

10 tools failed to install.

gocode:
Error: Command failed: /usr/local/go/bin/go get -u -v github.com/nsf/gocode
package github.com/nsf/gocode: cannot download, /home/bitnumbers/go is a GOROOT, not a GOPATH. For more details see: 'go help gopath'
package github.com/nsf/gocode: cannot download, /home/bitnumbers/go is a GOROOT, not a GOPATH. For more details see: 'go help gopath'

请建议。

2 个答案:

答案 0 :(得分:1)

正如您在评论中指出的那样,在您的系统上 echo $GOPATHecho $GOROOT会产生空输出。这表示go的安装不完整。现在,假设您已经通过网站上的下载或更好的go安装了gvm工具链,那么剩下要做的就是让环境在终端会话中保持更改。

添加

export GOPATH=*your path to GOPATH*
export GOROOT=*path to your go installation*

到你的~/.bashrc,重新启动终端会话,重新启动VSCode并重新尝试安装工具应该可以解决问题。

进一步阅读

https://golang.org/doc/install#install

https://github.com/golang/go/wiki/GOPATH

https://golang.org/doc/code.html#GOPATH

答案 1 :(得分:0)

我在 mac 中删除了所有旧的 Visual Studio Code。我安装了最新的 Visual Studio 代码,它解决了这个问题。 https://code.visualstudio.com/docs/setup/mac

这是我的 .bashrc 和 .bash_profile 设置:

export GOPATH=/Users/user/work
export GOROOT=/usr/local/Cellar/go/1.15.7/libexec
export PATH=$PATH:$GOROOT/bin