1. 首先安装Homerbrew,
过程中有遇到Mac下终端命令(如找不到curl命令 )找不到问题,最后参考博客Mac Terminal(终端)命令不能用予以解决。
2. 然后使用命令行直接安装Golang
brew install go
3. 配置GOPATH
调用go环境变量设置命令
go env
有如下结果
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH=""
GORACE=""
……
可见需要配置GOPATH和GOBIN
需要在在fishshell设置GOPATH,所以如果没有安装fish的需先安装:
brew install fish
在终端输入fish即可进入fish shell,然后配置GOPATH
huangdeMacBook-Pro:~ huangyuzhu$ fish
Welcome to fish, the friendly interactive shell
huangyuzhu@huangdeMacBook-Pro ~> set -gx GOPATH /usr/local/Cellar/go/1.9.2
在终端输入bash,配置GOBIN:
huangdeMacBook-Pro:~ huangyuzhu$ bash
bash-3.2$ vim .bash_profile
进入.bash_profile,在后面添加如下代码
export GOPATH=/usr/local/Cellar/go/1.9.2
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
这样就配置好了,再执行go env命令,可见配置如下:
GOARCH="amd64"
GOBIN="/usr/local/Cellar/go/1.9.2/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/usr/local/Cellar/go/1.9.2"
GORACE=""
……