VS?Code安裝go插件失敗原因分析以及解決方案
問(wèn)題背景
VSCode是我們開(kāi)發(fā)go程序的常用工具,但是安裝VSCode成功后,創(chuàng)建一個(gè).go文件會(huì)有如下提示:

這個(gè)是vscode提示你需要安裝go插件,但是當(dāng)你點(diǎn)擊install all進(jìn)行安裝時(shí),發(fā)現(xiàn)會(huì)安裝失敗。
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%
問(wèn)題原因
在安裝go插件時(shí),會(huì)自動(dòng)更新很多依賴庫(kù)文件,都是從Github更新下來(lái),但是因?yàn)镚ithub的文件中,多有應(yīng)用go官網(wǎng)中的文件,因?yàn)橐恍┚W(wǎng)絡(luò)國(guó)內(nèi)無(wú)法訪問(wèn),網(wǎng)絡(luò)緣故,不能直接下載,導(dǎo)致安裝失敗。
解決方案
方案1:快速方案
核心是配置國(guó)內(nèi)下載源,我們需要修改如下兩個(gè)go的環(huán)境配置:
go env -w GO111MODULE=on go env -w GOPROXY=https://goproxy.cn
配置好兩個(gè)變量后,重新打開(kāi)VSCode,點(diǎn)擊右下方的install all重新安裝,
或者,在vscode中使用Ctrl+Shift+P,輸入>go:install,下面會(huì)自動(dòng)搜索相關(guān)命令,我們選擇Go:Install/Update Tools這個(gè)命令,選中所有插件,點(diǎn)擊確定進(jìn)行安裝。
問(wèn)題成功解決:

方案2:環(huán)境變量中配置
Windows在電腦 -> 系統(tǒng) -> 高級(jí)系統(tǒng)設(shè)置 -> 用戶環(huán)境中分別新建GO111MODULE和GOPROXY兩個(gè)用戶變量,其值如下圖所示:
GO111MODULE=on GOPROXY=https://goproxy.cn,direct
或者也可以使用阿里源代理如下:
GO111MODULE=on GOPROXY=https://mirrors.aliyun.com/goproxy/
配置好之后,使用Windows + R調(diào)出終端,輸入cmd,通過(guò)go env命令查看go的環(huán)境變量配置是否設(shè)置成功。
方案3:vscode中配置
vscode編輯器的設(shè)置在:文件 -> 首選項(xiàng) -> 設(shè)置 -> 用戶 -> 應(yīng)用程序 -> 代理服務(wù)器路徑下,如下圖所示:

總結(jié)
到此這篇關(guān)于VS Code安裝go插件失敗原因分析以及解決方案的文章就介紹到這了,更多相關(guān)VS Code安裝go插件失敗解決內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Go語(yǔ)言輕量級(jí)線程Goroutine用法實(shí)例
這篇文章主要介紹了Go語(yǔ)言輕量級(jí)線程Goroutine用法,實(shí)例分析了goroutine使用技巧,需要的朋友可以參考下2015-02-02
golang 切片的三種使用方式及區(qū)別的說(shuō)明
這篇文章主要介紹了golang 切片的三種使用方式及區(qū)別的說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-04-04
Go語(yǔ)言獲取本機(jī)邏輯CPU數(shù)量的方法
這篇文章主要介紹了Go語(yǔ)言獲取本機(jī)邏輯CPU數(shù)量的方法,實(shí)例分析了runtime庫(kù)的操作技巧,需要的朋友可以參考下2015-03-03
Go語(yǔ)言開(kāi)發(fā)發(fā)送Get和Post請(qǐng)求的示例
這篇文章主要介紹了Go語(yǔ)言開(kāi)發(fā)發(fā)送Get和Post請(qǐng)求的示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-07-07
剖析Go編寫的Socket服務(wù)器模塊解耦及基礎(chǔ)模塊的設(shè)計(jì)
這篇文章主要介紹了Go的Socket服務(wù)器模塊解耦及日志和定時(shí)任務(wù)的模塊設(shè)計(jì),舉了一些Go語(yǔ)言編寫的服務(wù)器模塊的例子,需要的朋友可以參考下2016-03-03

