运行环境:win10(64位)、Win7(64位)
下载最新的go msi安装包,双击安装,然后配置GOPATH和GOROOT环境变量。
可以参考如下链接:https://studygolang.com/articles/17
2 下载并安装vscode程序
下载地址:https://code.visualstudio.com/download
选择windows下的64位vscode下载,下载之后双击安装。
打开vscode,然后点击上图中的图标,进入插件搜索界面,然后安装搜索到的go插件。
package main
import "fmt"
func main() {
var a = 10
fmt.Println("hello this new world %d!", a)
}
此时vscode在右下角会弹窗提示安装go相关工具,点击全部安装即可完成安装。此时,会提示安装10个工具,当前4个成功了,6个失败。如下所示
Installing github.com/nsf/gocode SUCCEEDED
Installing github.com/uudashr/gopkgs/cmd/gopkgsSUCCEEDED
Installing github.com/ramya-rao-a/go-outlineFAILED
Installing github.com/acroca/go-symbols FAILED
Installing golang.org/x/tools/cmd/guru FAILED
Installing golang.org/x/tools/cmd/gorename FAILED
Installing github.com/rogpeppe/godef SUCCEEDED
Installing github.com/sqs/goreturns FAILED
Installing github.com/golang/lint/golint FAILED
Installing github.com/derekparker/delve/cmd/dlvSUCCEEDED
参考链接:http://www.pythonsite.com/?p=429
命令行进入到如下目录:
cd%GOPATH%\src\github.com\golang
完成目录切换后,开始下载插件包(要事先安装git工具):
git clone https://github.com/golang/tools.git tools
将下载的tools目录下的所有文件手工拷贝到以下路径,如果没有此路径,请手工创建
%GOPATH%\src\golang.org\x\tools下
针对安装不成功的插件使用go命令再次进行安装
Installinggithub.com/ramya-rao-a/go-outline FAILED
go install github.com/ramya-rao-a/go-outline
Installinggithub.com/acroca/go-symbols FAILED
go install github.com/acroca/go-symbols
Installinggolang.org/x/tools/cmd/guru FAILED
go install golang.org/x/tools/cmd/guru
Installinggolang.org/x/tools/cmd/gorename FAILED
go install golang.org/x/tools/cmd/gorename
Installing github.com/sqs/goreturnsFAILED
go install github.com/sqs/goreturns
Installing github.com/golang/lint/golintFAILED
go install github.com/golang/lint/golint
注意:golint依然安装不成功,提示
src\github.com\golang\lint\golint\golint.go:19:2:cannot find package "golang.org/x/lint" in any of:
C:\Go\src\golang.org\x\lint (from $GOROOT)
D:\01.go\src\golang.org\x\lint (from $GOPATH)
将D:\01.go\src\github.com\golang\lint根据错误提示,拷贝至D:\01.go\src\golang.org\x\lint,然后再执行。(注意:D:\01.go是我的GOPATH路径,实际操作时请用你自己的实际路径)
go install github.com/golang/lint/golint
即可完成安装!