我是靠谱客的博主 含糊雨,这篇文章主要介绍VS Code 安装go插件失败分析及解决方案问题背景问题原因解决方案,现在分享给大家,希望可以做个参考。

问题背景

VSCode是我们开发go程序的常用工具,但是安装VSCode成功后,创建一个.go文件会有如下提示:

这个是vscode提示你需要安装go插件,但是当你点击install all进行安装时,发现会安装失败。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Installing 8 tools at D:pragramsgobin gocode gopkgs go-outline go-symbols dlv godef goreturns golint 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 github.com/derekparker/delve/cmd/dlv FAILED Installing github.com/rogpeppe/godef FAILED Installing github.com/sqs/goreturns FAILED Installing golang.org/x/lint/golint FAILED 8 tools failed to install. gocode: Error: Command failed: D:installgobingo.exe get -u -v github.com/mdempsky/gocode go: missing Git command. See https://golang.org/s/gogetcmd package github.com/mdempsky/gocode: exec: "git": executable file not found in %PATH% go: missing Git command. See https://golang.org/s/gogetcmd package github.com/mdempsky/gocode: exec: "git": executable file not found in %PATH% gopkgs: Error: Command failed: D:installgobingo.exe get -u -v github.com/uudashr/gopkgs/cmd/gopkgs go: missing Git command. See https://golang.org/s/gogetcmd package github.com/uudashr/gopkgs/cmd/gopkgs: exec: "git": executable file not found in %PATH% go: missing Git command. See https://golang.org/s/gogetcmd package github.com/uudashr/gopkgs/cmd/gopkgs: exec: "git": executable file not found in %PATH% go-outline: Error: Command failed: D:installgobingo.exe get -u -v github.com/ramya-rao-a/go-outline go: missing Git command. See https://golang.org/s/gogetcmd package github.com/ramya-rao-a/go-outline: exec: "git": executable file not found in %PATH% go: missing Git command. See https://golang.org/s/gogetcmd package github.com/ramya-rao-a/go-outline: exec: "git": executable file not found in %PATH% go-symbols: Error: Command failed: D:installgobingo.exe get -u -v github.com/acroca/go-symbols go: missing Git command. See https://golang.org/s/gogetcmd package github.com/acroca/go-symbols: exec: "git": executable file not found in %PATH% go: missing Git command. See https://golang.org/s/gogetcmd package github.com/acroca/go-symbols: exec: "git": executable file not found in %PATH% dlv: Error: Command failed: D:installgobingo.exe get -u -v github.com/derekparker/delve/cmd/dlv go: missing Git command. See https://golang.org/s/gogetcmd package github.com/derekparker/delve/cmd/dlv: exec: "git": executable file not found in %PATH% go: missing Git command. See https://golang.org/s/gogetcmd package github.com/derekparker/delve/cmd/dlv: exec: "git": executable file not found in %PATH% godef: Error: Command failed: D:installgobingo.exe get -u -v github.com/rogpeppe/godef go: missing Git command. See https://golang.org/s/gogetcmd package github.com/rogpeppe/godef: exec: "git": executable file not found in %PATH% go: missing Git command. See https://golang.org/s/gogetcmd package github.com/rogpeppe/godef: exec: "git": executable file not found in %PATH% goreturns: Error: Command failed: D:installgobingo.exe get -u -v github.com/sqs/goreturns go: missing Git command. See https://golang.org/s/gogetcmd package github.com/sqs/goreturns: exec: "git": executable file not found in %PATH% go: missing Git command. See https://golang.org/s/gogetcmd package github.com/sqs/goreturns: exec: "git": executable file not found in %PATH% golint: Error: Command failed: D:installgobingo.exe get -u -v golang.org/x/lint/golint go: missing Git command. See https://golang.org/s/gogetcmd package golang.org/x/lint/golint: exec: "git": executable file not found in %PATH% go: missing Git command. See https://golang.org/s/gogetcmd package golang.org/x/lint/golint: exec: "git": executable file not found in %PATH%

问题原因

 在安装go插件时,会自动更新很多依赖库文件,都是从Github更新下来,但是因为Github的文件中,多有应用go官网中的文件,因为一些网络国内无法访问,网络缘故,不能直接下载,导致安装失败。

解决方案

方案1:快速方案

核心是配置国内下载源,我们需要修改如下两个go的环境配置:

复制代码
1
2
3
go env -w GO111MODULE=on go env -w GOPROXY=https://goproxy.cn

配置好两个变量后,重新打开VSCode,点击右下方的install all重新安装,

或者,在vscode中使用Ctrl+Shift+P,输入>go:install,下面会自动搜索相关命令,我们选择Go:Install/Update Tools这个命令,选中所有插件,点击确定进行安装。

问题成功解决:

 方案2:环境变量中配置

Windows在电脑 -> 系统 -> 高级系统设置 -> 用户环境中分别新建GO111MODULE和GOPROXY两个用户变量,其值如下图所示:

复制代码
1
2
GO111MODULE=on GOPROXY=https://goproxy.cn,direct

或者也可以使用阿里源代理如下:

复制代码
1
2
3
4
5
GO111MODULE=on GOPROXY=https://mirrors.aliyun.com/goproxy/

配置好之后,使用Windows + R调出终端,输入cmd,通过go env命令查看go的环境变量配置是否设置成功。 

方案3:vscode中配置

vscode编辑器的设置在:文件 -> 首选项 -> 设置 -> 用户 -> 应用程序 -> 代理服务器路径下,如下图所示:

最后

以上就是含糊雨最近收集整理的关于VS Code 安装go插件失败分析及解决方案问题背景问题原因解决方案的全部内容,更多相关VS内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部