脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Golang - VS Code安装go插件失败原因分析以及解决方案

VS Code安装go插件失败原因分析以及解决方案

2022-09-08 17:22一越王超 Golang

vscode安装go插件时,由于各种原因,在安装插件时总是失败,下面这篇文章主要给大家介绍了关于VS Code安装go插件失败原因分析以及解决的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下

问题背景

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

VS Code安装go插件失败原因分析以及解决方案

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

Installing 8 tools at D:\pragrams\go\bin
  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:\install\go\bin\go.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:\install\go\bin\go.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:\install\go\bin\go.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:\install\go\bin\go.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:\install\go\bin\go.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:\install\go\bin\go.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:\install\go\bin\go.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:\install\go\bin\go.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
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这个命令,选中所有插件,点击确定进行安装。

问题成功解决:

VS Code安装go插件失败原因分析以及解决方案

方案2:环境变量中配置

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

?
1
2
GO111MODULE=on
GOPROXY=https://goproxy.cn,direct

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

?
1
2
GO111MODULE=on
GOPROXY=https://mirrors.aliyun.com/goproxy/  

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

方案3:vscode中配置

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

VS Code安装go插件失败原因分析以及解决方案

总结

到此这篇关于VS Code安装go插件失败原因分析以及解决方案的文章就介绍到这了,更多相关VS Code安装go插件失败解决内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/qq_36564503/article/details/124509832

延伸 · 阅读

精彩推荐
  • GolangGo 自定义package包设置与导入操作

    Go 自定义package包设置与导入操作

    这篇文章主要介绍了Go 自定义package包设置与导入操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...

    trouble-i-am-in6682021-06-21
  • Golang再次探讨go实现无限 buffer 的 channel方法

    再次探讨go实现无限 buffer 的 channel方法

    我们知道go语言内置的channel缓冲大小是有上限的,那么我们自己如何实现一个无限 buffer 的 channel呢?今天通过本文给大家分享go实现无限 buffer 的 channel方法...

    机智的小小帅5442021-08-08
  • GolangGo语言七篇入门教程四通道及Goroutine

    Go语言七篇入门教程四通道及Goroutine

    这篇文章主要为大家介绍了Go语言的通道及Goroutine示例详解,本文是Go语言七篇入门系列篇,有需要的朋友可以借鉴参考下,希望能够有所帮助...

    小生凡一6452021-12-01
  • Golanggolang strings包的Trim的使用说明

    golang strings包的Trim的使用说明

    这篇文章主要介绍了golang strings包的Trim的使用说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...

    kph_Hajash13312021-04-20
  • GolangGo语言快速入门图文教程

    Go语言快速入门图文教程

    Go是 Goolge 开发的一种静态型、编译型、并发型,并具有垃圾回收功能的语言,Go 语言上手非常容易,它的风格类似于 C 语言,Go 语言号称是互联网时代的...

    异常编程3992021-06-26
  • GolangGolang编程实现生成n个从a到b不重复随机数的方法

    Golang编程实现生成n个从a到b不重复随机数的方法

    这篇文章主要介绍了Golang编程实现生成n个从a到b不重复随机数的方法,结合实例形式分析了Go语言字符串操作及随机数生成的相关操作技巧,需要的朋友可以参...

    books19583142020-05-04
  • GolangGolang 实现插入排序的方法示例(2种)

    Golang 实现插入排序的方法示例(2种)

    这篇文章主要介绍了Golang 实现插入排序的方法示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下...

    邹友3712020-06-04
  • GolangGo日志框架zap增强及源码解读

    Go日志框架zap增强及源码解读

    这篇文章主要为大家介绍了Go日志框架zap增强及源码解读,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪...

    捉虫大师8722022-07-29