VS?Code安裝go插件失敗原因分析以及解決方案
問題背景
VSCode是我們開發(fā)go程序的常用工具,但是安裝VSCode成功后,創(chuàng)建一個.go文件會有如下提示:
這個是vscode提示你需要安裝go插件,但是當(dāng)你點擊install all進(jìn)行安裝時,發(fā)現(xiàn)會安裝失敗。
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的文件中,多有應(yīng)用go官網(wǎng)中的文件,因為一些網(wǎng)絡(luò)國內(nèi)無法訪問,網(wǎng)絡(luò)緣故,不能直接下載,導(dǎo)致安裝失敗。
解決方案
方案1:快速方案
核心是配置國內(nèi)下載源,我們需要修改如下兩個go的環(huán)境配置:
go env -w GO111MODULE=on go env -w GOPROXY=https://goproxy.cn
配置好兩個變量后,重新打開VSCode,點擊右下方的install all重新安裝,
或者,在vscode中使用Ctrl+Shift+P,輸入>go:install,下面會自動搜索相關(guān)命令,我們選擇Go:Install/Update Tools這個命令,選中所有插件,點擊確定進(jìn)行安裝。
問題成功解決:
方案2:環(huán)境變量中配置
Windows在電腦 -> 系統(tǒng) -> 高級系統(tǒng)設(shè)置 -> 用戶環(huán)境中分別新建GO111MODULE和GOPROXY兩個用戶變量,其值如下圖所示:
GO111MODULE=on GOPROXY=https://goproxy.cn,direct
或者也可以使用阿里源代理如下:
GO111MODULE=on GOPROXY=https://mirrors.aliyun.com/goproxy/
配置好之后,使用Windows + R調(diào)出終端,輸入cmd,通過go env命令查看go的環(huán)境變量配置是否設(shè)置成功。
方案3:vscode中配置
vscode編輯器的設(shè)置在:文件 -> 首選項 -> 設(shè)置 -> 用戶 -> 應(yīng)用程序 -> 代理服務(wù)器路徑下,如下圖所示:
總結(jié)
到此這篇關(guān)于VS Code安裝go插件失敗原因分析以及解決方案的文章就介紹到這了,更多相關(guān)VS Code安裝go插件失敗解決內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Go外部依賴包從vendor,$GOPATH和$GOPATH/pkg/mod查找順序
這篇文章主要介紹了Go外部依賴包vendor,$GOPATH和$GOPATH/pkg/mod下查找順序,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-12-12