GO开发环境、开发工具安装配置

windows安装

下载安装

Go官网下载地址:https://golang.org/dl/
GO开发环境、开发工具安装配置_第1张图片

由于网络问题大家可能打开有些慢,或者下载失败。大家也可以从下边下载。
下载执行后大家直接一路下一步就行了。

配置环境变量

(win+pause打开设置)--> 高级设置 --> 高级 --> 环境变量
GO开发环境、开发工具安装配置_第2张图片

配置GOPATH;他是用来存放你项目工程代码的地方。
然后将GOPATH 和 go安装的路劲配置到path中。
GO开发环境、开发工具安装配置_第3张图片

然后通过cmd执行go version查看版本,当看到版本后证明安装成功。

创建工程目录

在我们GOPATH中创建 bin pkg src
GO开发环境、开发工具安装配置_第4张图片

开发工具

go语言的开发工具有很多,这个根据个人的喜好进行选择。vscode、goland 、IntelliJ + Go 插件、LiteIDE等都行。他就是一个工具不用太纠结。

vscode+go插件

mac和window安装一样的。去官网下载https://code.visualstudio.com/download
在vscode中搜索go,然后安装。为了方便使用你可以先安装一个中文插件。
GO开发环境、开发工具安装配置_第5张图片

安装成功后在安装go语言开发工具安装包(代码提示,代码自动补全等功能)。
shift+ctrl+p 然后输入go:install选择Go:Install/Update Tools
GO开发环境、开发工具安装配置_第6张图片

全选,然后安装。
GO开发环境、开发工具安装配置_第7张图片

安装问题解决

如果安装过程中显示如下无法安装。

Tools environment: GOPATH=C:\workspace\goproject
Installing 10 tools at C:\workspace\goproject\bin in module mode.
  gopkgs
  go-outline
  gotests
  gomodifytags
  impl
  goplay
  dlv
  dlv-dap
  staticcheck
  gopls

Installing github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest FAILED
{
 "killed": false,
 "code": 1,
 "signal": null,
 "cmd": "C:\\Program Files\\Go\\bin\\go.exe install -v github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest",
 "stdout": "",
 "stderr": "go install: github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest: module github.com/uudashr/gopkgs/v2/cmd/gopkgs: Get \"https://proxy.golang.org/github.com/uudashr/gopkgs/v2/cmd/gopkgs/@v/list\": dial tcp 172.217.27.145:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.\n"
}
Installing github.com/ramya-rao-a/go-outline@latest FAILED
{
 "killed": false,
 "code": 1,
 "signal": null,
 "cmd": "C:\\Program Files\\Go\\bin\\go.exe install -v github.com/ramya-rao-a/go-outline@latest",
 "stdout": "",
 "stderr": "go install: github.com/ramya-rao-a/go-outline@latest: module github.com/ramya-rao-a/go-outline: Get \"https://proxy.golang.org/github.com/ramya-rao-a/go-outline/@v/list\": dial tcp 172.217.27.145:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.\n"
}
Installing github.com/cweill/gotests/gotests@latest FAILED
{
 "killed": false,
 "code": 1,
 "signal": null,
 "cmd": "C:\\Program Files\\Go\\bin\\go.exe install -v github.com/cweill/gotests/gotests@latest",
 "stdout": "",
 "stderr": "go install: github.com/cweill/gotests/gotests@latest: module github.com/cweill/gotests/gotests: Get \"https://proxy.golang.org/github.com/cweill/gotests/gotests/@v/list\": dial tcp 172.217.27.145:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.\n"
}
Installing github.com/fatih/gomodifytags@latest FAILED
{
 "killed": false,
 "code": 1,
 "signal": null,
 "cmd": "C:\\Program Files\\Go\\bin\\go.exe install -v github.com/fatih/gomodifytags@latest",
 "stdout": "",
 "stderr": "go install: github.com/fatih/gomodifytags@latest: module github.com/fatih/gomodifytags: Get \"https://proxy.golang.org/github.com/fatih/gomodifytags/@v/list\": dial tcp 172.217.27.145:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.\n"
}
Installing github.com/josharian/impl@latest FAILED
{
 "killed": false,
 "code": 1,
 "signal": null,
 "cmd": "C:\\Program Files\\Go\\bin\\go.exe install -v github.com/josharian/impl@latest",
 "stdout": "",
 "stderr": "go install: github.com/josharian/impl@latest: module github.com/josharian/impl: Get \"https://proxy.golang.org/github.com/josharian/impl/@v/list\": dial tcp 142.251.42.241:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.\n"
}

原因是网络问题。懂得都懂。我们只需配置一下国内的代理重新下载安装一下插件就好了。

go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.io,direct

你可能感兴趣的:(golang)