1.安装
下载地址(https://golang.org/dl/)
下载之后,双击安装;
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
|
3.环境变量介绍
3.1 GOROOT
golang
的安装路径,MAC
环境下安装后,默认在(/usr/local/go
)
3.2 GOPATH
可以理解为工作目录,该目录下约定有三个子目录,分别为:src、pkg、bin
;
当我们使用go install
命令编译和打包应用程序时,该命令会将编译后二进制程序文件 存放到GOBIN
目录下,一般我们将GOBIN
设置为$GOPATH/bin
目录。
4.修改配置
4.1 配置GOPATH、GOBIN
Go
安装后默认GOPATH
为: $HOME/go
(这里是cd /Users/hui/go
);
修改.bash_profile
,如果安装了zsh
客户端需要修改.zshrc
;
export GOPATH=/Users/hui/Project/Go
export GOBIN=$GOPATH/bin
|