赞
踩
下载地址 https://studygolang.com/dl
选择下载 go1.19.4.windows-amd64.msi
点击安装包,默认一直next 默认会安装到 C:\Program Files\Go
安装完成后,打开cmd 或者 powershell
输入 go version 验证是否安装成功
$ go version
go version go1.19.4 windows/amd64
GOROOT其实就是Golang的安装目录。新版本的GOROOT已经不需要设置了。Golang编译器安装后,会自动把%GOROOT%\bin目录添加到环境变量PATH。
GOPATH指向的目录,理解为工作目录,其作用是告诉Go命令和其它相关工具,在哪里找系统上安装的Go包。
默认的GOPATH是**%USERPROFILE%\go**。
Go1.14
及之后的版本中启用了Go Module模式之后,不一定非要将代码写到GOPATH目录下,所以也就不需要我们再自己配置GOPATH了,使用默认的即可。
由于国内的网络环境问题,我们可以通过配置GOPROXY避免DNS污染导致的模块拉取缓慢或失败的问题,加速你的构建
默认配置
GOPROXY=https://proxy.golang.org,direct
修改 GOPROXY
go env -w GOPROXY=https://goproxy.cn,direct
查看go环境设置,命令: go env
$ go env set GO111MODULE= set GOARCH=amd64 set GOBIN= set GOCACHE=C:\Users\zhuhuijie\AppData\Local\go-build set GOENV=C:\Users\zhuhuijie\AppData\Roaming\go\env set GOEXE=.exe set GOEXPERIMENT= set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOINSECURE= set GOMODCACHE=C:\Users\zhuhuijie\go\pkg\mod set GONOPROXY= set GONOSUMDB= set GOOS=windows set GOPATH=C:\Users\zhuhuijie\go set GOPRIVATE= set GOPROXY=https://proxy.golang.org,direct set GOROOT=C:\Program Files\Go set GOSUMDB=sum.golang.org set GOTMPDIR= set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64 set GOVCS= set GOVERSION=go1.19.4 set GCCGO=gccgo set GOAMD64=v1 set AR=ar set CC=gcc set CXX=g++ set CGO_ENABLED=1 set GOMOD=NUL set GOWORK= 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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\ZHUHUI~1\AppData\Local\Temp\go-build3394306368=/tmp/go-build -gno-record-gcc-switches PS C:\Users\zhuhuijie> go env -w GOPROXY=https://goproxy.cn,direct PS C:\Users\zhuhuijie> go env -w GO111MODULE=on PS C:\Users\zhuhuijie> PS C:\Users\zhuhuijie> PS C:\Users\zhuhuijie> PS C:\Users\zhuhuijie> PS C:\Users\zhuhuijie> go env set GO111MODULE=on set GOARCH=amd64 set GOBIN= set GOCACHE=C:\Users\zhuhuijie\AppData\Local\go-build set GOENV=C:\Users\zhuhuijie\AppData\Roaming\go\env set GOEXE=.exe set GOEXPERIMENT= set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOINSECURE= set GOMODCACHE=C:\Users\zhuhuijie\go\pkg\mod set GONOPROXY= set GONOSUMDB= set GOOS=windows set GOPATH=C:\Users\zhuhuijie\go set GOPRIVATE= set GOPROXY=https://goproxy.cn,direct set GOROOT=C:\Program Files\Go set GOSUMDB=sum.golang.org set GOTMPDIR= set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64 set GOVCS= set GOVERSION=go1.19.4 set GCCGO=gccgo set GOAMD64=v1 set AR=ar set CC=gcc set CXX=g++ set CGO_ENABLED=1 set GOMOD=NUL set GOWORK= 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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\ZHUHUI~1\AppData\Local\Temp\go-build1050900026=/tmp/go-build -gno-record-gcc-switches
创建helloWorld.go 文件并编辑内容如下
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}
运行
$ go run helloWorld.go
Hello World!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。