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)更新很多依賴(lài)庫(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è)置 -> 用戶(hù)環(huán)境中分別新建GO111MODULE和GOPROXY兩個(gè)用戶(hù)變量,其值如下圖所示:
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è)置 -> 用戶(hù) -> 應(yīng)用程序 -> 代理服務(wù)器路徑下,如下圖所示:
總結(jié)
到此這篇關(guān)于VS Code安裝go插件失敗原因分析以及解決方案的文章就介紹到這了,更多相關(guān)VS Code安裝go插件失敗解決內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
go單例實(shí)現(xiàn)雙重檢測(cè)是否安全的示例代碼
這篇文章主要介紹了go單例實(shí)現(xiàn)雙重檢測(cè)是否安全,本文給大家分享雙重檢驗(yàn)示例代碼,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03Go外部依賴(lài)包從vendor,$GOPATH和$GOPATH/pkg/mod查找順序
這篇文章主要介紹了Go外部依賴(lài)包vendor,$GOPATH和$GOPATH/pkg/mod下查找順序,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-12-12go語(yǔ)言入門(mén)環(huán)境搭建及GoLand安裝教程詳解
這篇文章主要介紹了go語(yǔ)言入門(mén)環(huán)境搭建及GoLand安裝教程詳解,需要的朋友可以參考下2020-12-12Golang Http請(qǐng)求返回結(jié)果處理
本文主要介紹了Golang Http請(qǐng)求返回結(jié)果處理,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08Golang使用Gin實(shí)現(xiàn)文件上傳的示例代碼
本文我們主要介紹了Golang如何使用Gin實(shí)現(xiàn)文件上傳,Go標(biāo)準(zhǔn)庫(kù)net/http對(duì)文件上傳已經(jīng)提供了非常完善的支持,而Gin框架在其基礎(chǔ)上進(jìn)一步封裝,因此使用Gin開(kāi)發(fā)文件上傳功能時(shí),只需要簡(jiǎn)單幾行代碼便可以實(shí)現(xiàn),需要的朋友可以參考下2024-02-02