一、下载安装
下载地址:golang.google.cn/dl/ 可以下载对应不同平台版本的安装包,此处用的是windows版本
想要下载其他版本可以从 Stable versions/Archived versions 中查找
D:\Develop\Go
安装后的目录如所示
二、环境变量配置
1.右键选择计算机--> 选择系统属性
2.选择高级系统设置
3.点击环境变量
4.编辑环境变量
5.新建环境变量,配置的目录是 Golang安装包目录下的bin目录
- 使用WIN+R 输入cmd ,输入 go version 查看
7配置 Golang
C:\Users\THINKPAD>go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\THINKPAD\AppData\Local\go-build
set GOENV=C:\Users\THINKPAD\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\THINKPAD\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\THINKPAD\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=D:\Develop\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\Develop\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.1
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\THINKPAD\AppData\Local\Temp\go-build308072410=/tmp/go-build -gno-record-gcc-switches
复制代码
执行命令 set GO111MODULE=on
C:\Users\THINKPAD>set GO111MODULE=on
复制代码
set GOPROXY=http://goproxy.cn
复制代码
再执行 go env 命令查看 可以看到 GO111MODULE 和 GOPROXY 属性已经变更
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\THINKPAD\AppData\Local\go-build
set GOENV=C:\Users\THINKPAD\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\THINKPAD\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\THINKPAD\go
set GOPRIVATE=
set GOPROXY=http://goproxy.cn
set GOROOT=D:\Develop\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\Develop\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.1
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\THINKPAD\AppData\Local\Temp\go-build421255579=/tmp/go-build -gno-record-gcc-switches
复制代码
至此,windows 下的 go 语言环境搭建完成