Golang
是Google開發(fā)的一種編譯型,平行化谚殊,具有垃圾回收功能的編譯語言,還和C一樣有指針戈鲁。
Golang
是天生的網(wǎng)絡編程語言仇参,學習使用Golang
先從環(huán)境配置開始。
環(huán)境要求:
-
Homerbrew
安裝參考:http://brew.sh/
安裝Golang
Golang
可以通過源代碼自己編譯安裝https://golang.org/project/,為了管理和升級建議使用Homerbrew
安裝婆殿。
使用命令行直接安裝Golang
:
brew install go
==> Downloading https://homebrew.bintray.com/bottles/go-1.7.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring go-1.7.el_capitan.bottle.tar.gz
==> Caveats
As of go 1.2, a valid GOPATH is required to use the `go get` command:
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/bin
==> Summary
?? /usr/local/Cellar/go/1.7: 6,435 files, 250.6M
從提示中可以看出需要設置GOPATH
和GOROOT
的環(huán)境變量诈乒,以及設置PATH
.
配置GOPATH
查看go 的環(huán)境變量設置的命令
go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.6/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.6/libexec/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT=""
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
需要設置的環(huán)境變量包括:GOPATH
,GOBIN
以及把GOBIN加入到PATH
中,GOROOT
變量默認已經(jīng)設置好。
在fishshell
設置GOPATH:
set -gx GOPATH /usr/local/Cellar/go/1.7.6
在bash
中設置:
vim .bash_profile
export GOPATH=/usr/local/Cellar/go/1.7.6
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
使修改立刻生效:
source .bash_profile
再看下go的環(huán)境變量:
go env
GOARCH="amd64"
GOBIN="/usr/local/Cellar/go/1.7.6/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/usr/local/Cellar/go/1.7.6"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.6/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.6/libexec/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT=""
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
環(huán)境變量設置完成!