1.安装
下载之后,双击安装;
2.验证
2.1 查看版本
# 查看版本
➜ ~ go version
go version go1.15.5 darwin/amd64
2.2 查看Go变量
# 查看环境变量
➜ ~ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hui/Library/Caches/go-build"
GOENV="/Users/hui/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/hui/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/hui/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/8f/vnx2y1h57nzbd2p4vtcl6hv80000gn/T/go-build487191191=/tmp/go-build -gno-record-gcc-switches -fno-common"
2.3 查看环境变量PATH
➜ Go echo $PATH
/usr/local/opt/ncurses/bin:/usr/local/opt/icu4c/sbin:/usr/local/opt/icu4c/bin:/Users/hui/.nvm/versions/node/v12.3.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Users/hui/DevEnvSpace/maven-3.6.3/bin
# 可以看出/usr/local/go/bin 已经存在
3.环境变量介绍
3.1 GOROOT
golangMAC/usr/local/go
3.2 GOPATH
src、pkg、bin
src.go .c .h .sgolanggo run,go installpkg.abin$PATHGOPATH${GOPATH//://bin:}/binbin
go installGOBINGOBIN$GOPATH/bin
4.修改配置
4.1 配置GOPATH、GOBIN
GoGOPATH$HOME/gocd /Users/hui/go
.bash_profileiTerm2.zshrc
## Go项目工作空间
export GOPATH=/Users/hui/Project/Go
## 存放编译后二进制文件的目录
export GOBIN=$GOPATH/bin