go语言官网:https://golang.google.cn/
go中文网:https://studygolang.com/dl
下载相应的软件包
现在最新版本是1.18版本
你也可以使用1.17版本,都可以。
安装:
双击开始安装
选择合适的路径安装
我的安装路径:
不要忘记你安装的路径,所以尽可能用个好记的名字
开始安装
点击install就开始安装了。
测试
安装完成之后开始测试:
打开CMD 输入go
查看版本使用:version
配置变量 GOPATH
GOPATH 是 Go语言中使用的一个环境变量,它使用绝对路径提供项目的工作目录(workspace)。
GOPATH下创建src文件夹,即存放Go项目代码的位置。
搜索:
新建一个目录,用来存放后期写的代码:
GoWork有三个目录
src // 存储go的源代码(需要我们自己手动创建)
pkg // 存储编译后生成的包文件 (自动生成)
bin // 存储生成的可执行文件(自动生成)
配置好后,查看环境变量:
C:\Users\xinsz08>go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\xinsz08\AppData\Local\go-build
set GOENV=C:\Users\xinsz08\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=E:\GoWork\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=E:\GoWork
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=E:\golang_install_win
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=E:\golang_install_win\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.5
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=D:\Temp\go-build1159393017=/tmp/go-build -gno-record-gcc-switches
其中: GOROOT表示开发包的安装目录
补充:
执行完go之后出来的参数
C:\Users\xinsz08>go
Go is a tool for managing Go source code.
Usage:
go <command> [arguments]
The commands are:
bug start a bug report ## bug 报告
build compile packages and dependencies## 构建包和依赖项
clean remove object files and cached files ## 清楚缓存文件和对象
doc show documentation for package or symbol
env print Go environment information
fix update packages to use new APIs
fmt gofmt (reformat) package sources
generate generate Go files by processing source
get add dependencies to current module and install them
install compile and install packages and dependencies ## 安装编译依赖项
list list packages or modules
mod module maintenance
run compile and run Go program ## 运行go程序
test test packages
tool run specified go tool
version print Go version ## 打印版本
vet report likely mistakes in packages
Use "go help <command>" for more information about a command.
Additional help topics:
buildconstraint build constraints
buildmode build modes
c calling between Go and C
cache build and test caching
environment environment variables
filetype file types
go.mod the go.mod file
gopath GOPATH environment variable
gopath-get legacy GOPATH go get
goproxy module proxy protocol
importpath import path syntax
modules modules, module versions, and more
module-get module-aware go get
module-auth module authentication using go.sum
packages package lists and patterns
private configuration for downloading non-public code
testflag testing flags
testfunc testing functions
vcs controlling version control with GOVCS
Use "go help <topic>" for more information about that topic.
C:\Users\xinsz08>
总结
go相对来说,安装比较简单,傻瓜式安装,在Linux和mac的安装大家找一下其他资料。