【Go】VScode安装Go插件

一、go语言安装

go语言下载地址:https://studygolang.com/dl

1、添加环境变量

go语言安装完成后,还得定义两个环境变量:GOPATH(go的工作目录地址)和GOROOT(go语言安装地址),建议写在用户变量中便于VSCode找到。

一般用默认安装go语言完成后,会自动将go语言安装目录下的bin目录添加到Path中,但如果你自定义安装目录,那么就得自己去手动修改这个path变量;

2、检查go语言是否安装成功

如果输入命令看不到版本,那么需要查看环境变量配置是否有问题,修改环境变量后需要重启电脑使环境变量生效。(如果你看到我这个终端惊叹:“诶,你这个终端怎么这么好看!给我也整一个”,我不告诉你可以参考这篇博客:https://blog.csdn.net/BobYuan888/article/details/100626886

二、VSCode中安装第三方go语言插件

1、在VSCode中安装Go插件

 

2、报错:Failed to run "go env" to find GOPATH as the "go" binary cannot be found in either GOROOT(undefined) or PATH

        出现这种报错有两种可能:一是你在第一步安装时不是安装在默认目录,那么需要手动修改环境变量,并重启生效。二是没有定义GOROOT变量。

 

3、提示安装go插件:The "go-outline" command is not available. Run "go get -v github.com/ramya-rao-a/go-outline"to install。

报错:

Installing github.com/mdempsky/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/go-delve/delve/cmd/dlv SUCCEEDED
Installing github.com/stamblerre/gocode FAILED
Installing github.com/rogpeppe/godef SUCCEEDED
Installing github.com/sqs/goreturns FAILED
Installing golang.org/x/lint/golint FAILED

        这是因为go是谷歌的,因为某种强大的未知力量无法访问。因此需要替代的安装源。方法是:进入go的工作目录,创建/src/golang.org/x子目录,在该子目录下运行 git clone命令,提示:需要先安装git。

git clone https://github.com/golang/tools.git 
git clone https://github.com/golang/lint.git
git clone https://github.com/golang/sync.git

然后再重新启动VSCode,重新安装插件,安装速度有点慢,请耐心等待。如果还安装失败,可以多试几次重启VSCode安装。

最后提示"All tools successfully installed.You are ready to Go .",则说明安装成功:)。

参考:https://www.cnblogs.com/dfsxh/articles/11918051.html

猜你喜欢

转载自blog.csdn.net/BobYuan888/article/details/104581850