使用Homebrew安装Golang
1、安装Homebrew
Section titled “1、安装Homebrew”安装步骤,参考Homebew
2、安装Golang
Section titled “2、安装Golang”$ brew install go2.1、查看Golang安装信息
Section titled “2.1、查看Golang安装信息”$ brew info gogo: stable 1.9.2 (bottled), devel 1.10beta1, HEADOpen source programming language to build simple/reliable/efficient softwarehttps://golang.org/usr/local/Cellar/go/1.8.3 (7,035 files, 282.0MB) Poured from bottle on 2017-09-05 at 09:29:02/usr/local/Cellar/go/1.9 (7,639 files, 293.7MB) Poured from bottle on 2017-09-05 at 09:45:50/usr/local/Cellar/go/1.9.2 (7,646 files, 293.9MB) * Poured from bottle on 2018-01-09 at 16:50:46From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/go.rb==> RequirementsBuild: git ✔Required: macOS >= 10.8 ✔==> Options--without-cgo Build without cgo (also disables race detector)--without-race Build without race detector--devel Install development version 1.10beta1--HEAD Install HEAD version==> CaveatsA valid GOPATH is required to use the `go get` command.If $GOPATH is not specified, $HOME/go will be used by default: https://golang.org/doc/code.html#GOPATH
You may wish to add the GOROOT-based install location to your PATH: export PATH=$PATH:/usr/local/opt/go/libexec/bin2.3、设置GOROOT、GOPATH
Section titled “2.3、设置GOROOT、GOPATH”编辑配置文件~/.zshrc, 更新内容:
export GOPATH=/Users/xiaoxiwang/go:/Users/xiaoxiwang/Documents/demo/golangDemoexport GOROOT=/usr/local/opt/go/libexecexport PATH=$PATH:/Users/xiaoxiwang/anaconda3/bin:/usr/local/opt/go/libexec/bin保存修改,更新配置
source ~/.zshrc2.4、安装完成
查看安装的golang信息:
$ go envGOARCH="amd64"GOBIN=""GOEXE=""GOHOSTARCH="amd64"GOHOSTOS="darwin"GOOS="darwin"GOPATH="/Users/xiaoxiwang/go:/Users/xiaoxiwang/Documents/demo/golangDemo"GORACE=""GOROOT="/usr/local/opt/go/libexec"GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"GCCGO="gccgo"CC="clang"GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/2s/5xlkp2f149j5bydw1rhxhyfw0000gn/T/go-build390073932=/tmp/go-build -gno-record-gcc-switches -fno-common"CXX="clang++"CGO_ENABLED="1"CGO_CFLAGS="-g -O2"CGO_CPPFLAGS=""CGO_CXXFLAGS="-g -O2"CGO_FFLAGS="-g -O2"CGO_LDFLAGS="-g -O2"PKG_CONFIG="pkg-config"