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

作者:一越王超 时间:2024-04-26 17:24:08 

问题背景

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的环境配置:

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两个用户变量,其值如下图所示:

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

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

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

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

方案3:vscode中配置

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

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

来源:https://blog.csdn.net/qq_36564503/article/details/124509832

标签:vscode,go插件,失败
0
投稿

猜你喜欢

  • 使用Python的urllib2模块处理url和图片的技巧两则

    2022-02-15 21:26:00
  • 如何利用python实现词频统计功能

    2021-05-01 16:38:21
  • 自动定时重启sql server回收内存

    2008-11-26 17:41:00
  • Python基于Socket实现的简单聊天程序示例

    2022-12-22 09:14:50
  • python 限制函数调用次数的实例讲解

    2023-11-11 00:34:23
  • Python基础学习之反射机制详解

    2023-02-15 11:02:01
  • 使用网际数据库浏览器在线维护Access数据库

    2008-05-23 13:05:00
  • archlinux 罗技K380 F1-F12 功能键锁定(实现方法)

    2023-11-27 22:42:48
  • Python爬虫之爬取二手房信息

    2021-08-11 19:40:50
  • jQuery 让人恋恋不舍的秘密

    2010-01-20 10:09:00
  • SQL使用ROW_NUMBER() OVER函数生成序列号

    2024-01-18 18:14:35
  • Python统计时间内的并发数代码实例

    2022-02-17 18:24:16
  • 如何往SQL Server数据库传递日期数据?

    2010-06-08 09:29:00
  • 取numpy数组的某几行某几列方法

    2022-03-10 02:04:56
  • 使用PyV8在Python爬虫中执行js代码

    2022-05-09 14:33:36
  • Python快速查找list中相同部分的方法

    2021-01-28 17:26:00
  • python实现通过代理服务器访问远程url的方法

    2023-03-14 00:47:38
  • python使用nibabel和sitk读取保存nii.gz文件实例

    2021-03-11 16:12:53
  • python Django框架实现自定义表单提交

    2021-01-04 14:52:42
  • Python3标准库之dbm UNIX键-值数据库问题

    2024-01-26 15:56:11
  • asp之家 网络编程 m.aspxhome.com