Mac上go环境配置

mwrx6905 9年前
   <h2>使用Homebrew 安装go语言sdk</h2>    <p> </p>    <blockquote>     <p>brew install go</p>    </blockquote>    <p>==> Downloading <a href="/misc/goto?guid=4959670653644424031">https://homebrew.bintray.com/bottles/go-1.5.1.el_capitan.bottle.</a><br> Already downloaded: /Library/Caches/Homebrew/go-1.5.1.el_capitan.bottle.tar.gz<br> ==> Pouring go-1.5.1.el_capitan.bottle.tar.gz<br> ==> Caveats<br> As of go 1.2, a valid GOPATH is required to use the <code>go get</code> command:<br> <a href="/misc/goto?guid=4959670653736572787">https://golang.org/doc/code.html#GOPATH</a></p>    <p>You may wish to add the GOROOT-based install location to your PATH:<br> export PATH=$PATH:/usr/local/opt/go/libexec/bin<br> ==> Summary<br> ? /usr/local/Cellar/go/1.5.1: 5330 files, 273M</p>    <h2>配置GOPATH</h2>    <p>查看go 的环境变量设置</p>    <blockquote>     <p>go env</p>    </blockquote>    <pre>  GOARCH="amd64"  GOBIN=""  GOEXE=""  GOHOSTARCH="amd64"  GOHOSTOS="darwin"  GOOS="darwin"  GOPATH=""  GORACE=""  GOROOT="/usr/local/Cellar/go/1.5.1/libexec"  GOTOOLDIR="/usr/local/Cellar/go/1.5.1/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"  </pre>    <p>需要设置环境变量<code>GOPATH</code> ,<code>GOBIN</code> 以及把GOBIN加入到<code>PATH</code>中</p>    <p>在fishshell设置GOPATH<br> <code>set -gx GOPATH /usr/local/Cellar/go/1.5.1</code></p>    <blockquote>     <p>vim .bash_profile</p>    </blockquote>    <pre>  export GOPATH=/usr/local/Cellar/go/1.5.1  export GOBIN=$GOPATH/bin  export PATH=$PATH:$GOBIN  </pre>    <blockquote>     <p>source .bash_profile</p>    </blockquote>    <p>再看下go的环境变量</p>    <blockquote>     <p>go env</p>    </blockquote>    <pre>  GOARCH="amd64"  GOBIN="/usr/local/Cellar/go/1.5.1/bin"  GOEXE=""  GOHOSTARCH="amd64"  GOHOSTOS="darwin"  GOOS="darwin"  GOPATH="/usr/local/Cellar/go/1.5.1"  GORACE=""  GOROOT="/usr/local/Cellar/go/1.5.1/libexec"  GOTOOLDIR="/usr/local/Cellar/go/1.5.1/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"  </pre>    <p>环境变量设置成功!</p>    <p> </p>    <p>来自: <a href="/misc/goto?guid=4959670653816141029" rel="nofollow">https://segmentfault.com/a/1190000003933557</a></p>