Golang是Google開發的一種編譯型,平行化程式設計語言。具有簡潔、快速、安全。善於記憶體管理、數組安全,並且編譯迅速
Go語言設計支援主流的32位和64位的x86平台,同時也支援32位的ARM架構。Go語言在Go1版本上支援Windows, 蘋果Mac OS X, Linux和FreeBSD作業系統。
當然,一切語言的學習都從搭建環境開始(macOS)
使用 HomeBrew 安裝
Homebrew 安裝參考:http://brew.sh/
$ brew install go
==> Downloading https://homebrew.bintray.com/bottles/go-1.10.3.high_sierra.bottlAlready downloaded: /Users/faremax/Library/Caches/Homebrew/go-1.10.3.high_sierra.bottle.tar.gz==> Pouring go-1.10.3.high_sierra.bottle.tar.gz==> 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#GOPATHYou may wish to add the GOROOT-based install location to your PATH: export PATH=$PATH:/usr/local/opt/go/libexec/bin==> Summary /usr/local/Cellar/go/1.10.3: 8,170 files, 336.7MB
安裝成功後需要配置一下環境變數,在~/.bash_profile
中添加以下內容:
#golangexport GOPATH=$HOME/goexport GOBIN=$GOPATH/binexport PATH=$PATH:$GOBIN
這裡可以看出需要設定GOPATH和GOBIN的環境變數,以及設定PATH.
為使修改立刻生效,執行:
$ source .bash_profile
查看配置是否生效:
$ go env
得到如下內容:
GOARCH="amd64"GOBIN="/Users/faremax/go/bin"GOCACHE="/Users/faremax/Library/Caches/go-build"GOEXE=""GOHOSTARCH="amd64"GOHOSTOS="darwin"GOOS="darwin"GOPATH="/Users/faremax/go"GORACE=""GOROOT="/usr/local/Cellar/go/1.10.3/libexec"GOTMPDIR=""GOTOOLDIR="/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64"GCCGO="gccgo"CC="clang"CXX="clang++"CGO_ENABLED="1"CGO_CFLAGS="-g -O2"CGO_CPPFLAGS=""CGO_CXXFLAGS="-g -O2"GOARCH="amd64"GOBIN="/Users/faremax/go/bin"GOCACHE="/Users/faremax/Library/Caches/go-build"GOEXE=""GOHOSTARCH="amd64"GOHOSTOS="darwin"GOOS="darwin"GOPATH="/Users/faremax/go"GORACE=""GOROOT="/usr/local/Cellar/go/1.10.3/libexec"GOTMPDIR=""GOTOOLDIR="/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64"GCCGO="gccgo"CC="clang"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"GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/f0/wl0qf7mn1131dc3brmbb3_d00000gn/T/go-build994213970=/tmp/go-build -gno-record-gcc-switches -fno-common"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/f0/wl0qf7mn1131dc3brmbb3_d00000gn/T/go-build994213970=/tmp/go-build -gno-record-gcc-switches -fno-common"
可以看到,配置生效,環境變數設定完成!