mac下使用brew安裝並使用golang

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

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

安裝 
通過執行命令

brew search go

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

brew install go@1.7

安裝好了,按網上的教程 直接在終端裡執行 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=”” 
GOROOT=”/usr/local/opt/go@1.7/bin” 
GOTOOLDIR=”/usr/local/opt/go@1.7/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 ,輸入 /usr/local/Cellar/go@1.7/1.7.6,open,然後就會出現1.7版本的go了。

嗯,剩下的就是開工啦~

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.