建立Golang开发环境

安装Golang

1
$ brew install go

设置环境变量GOROOT

1
2
3
4
5
6
7
8
$ which go
/usr/local/bin/go
$ readlink /usr/local/bin/go
../Cellar/go/1.4.1/bin/go
$ echo $GOROOT
/usr/local/Cellar/go/1.4.1/libexec/

设置环境变量GOPATH

Golang有工作区的概念,一个工作区包含三个子目录:

  • src
  • pkg
  • bin

而GOPATH变量就是该工作区目录的路径:

1
2
export GOPATH=/Users/LeslieZhu/golang/
export PATH=$PATH:$GOPATH/bin/
吴羽舒 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!