1. 程式人生 > >mac下使用brew安裝並使用golang

mac下使用brew安裝並使用golang

最新版 cell jet g++ tool 下載安裝 mac dir 命令

突然想進go坑,然後就嘗試在公司新發的mac上折騰下

安裝
通過執行命令

brew search go

看到可用最新版是1.7,就他了

brew install [email protected]

安裝好了,按網上的教程 直接在終端裏執行 go,結果提示命令不存在 Orz。好吧,自己加個別名吧。
打開 .bash_profile,添加:

alias go=’/usr/local/Cellar/go\@1.7/1.7.6/bin/go’

執行 source .bash_profile,然後再執行 go。一切正常~

按照教程,然後繼續在 .bash_profile 中設置幾個環境變量:

export GOROOT=/usr/local/opt/go\@1.7/bin/
export GOPATH=~/code/golang/ # 這是我的項目路徑
export GOBIN=$GOPATH/bin
export PATH=GOBIN

然後執行 go env

GOARCH=”amd64”
GOBIN=”/Users/atai/code/golang//bin”
GOEXE=””
GOHOSTARCH=”amd64”
GOHOSTOS=”darwin”
GOOS=”darwin”
GOPATH=”/Users/atai/code/golang/”
GORACE=””
[email protected]

*//bin”
[email protected]/bin/pkg/tool/darwin_amd64”
CC=”clang”
GOGCCFLAGS=”-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/37/4py2jv5d4pvcf61kz4tf7q800000gn/T/go-build735656329=/tmp/go-build -gno-record-gcc-switches -fno-common”
CXX=”clang++”
CGO_ENABLED=”1”

完美(づ??????)づ

IDE
jetbrain的ide習慣了,所以直接去官網下載安裝了Gogland。難得免費 (??????)??

打開Gogland寫了hello world準備跑,結果提示要在ide裏設置下GOROOT。好吧,打開選擇目錄的彈窗後,按 command+shift+g ,輸入 [email protected]/1.7.6,open,然後就會出現1.7版本的go了。

嗯,剩下的就是開工啦~

mac下使用brew安裝並使用golang