在Homebrew複製安裝命令,在控制檯運行完成安裝golang
$ brew update && brew upgrade $ brew install go
建立一個目錄做爲gopath
,在目錄建立三個目錄bin
、src
、pkg
vim
$ cd ~ $ vim .bash_profile
編輯.bash_profile
文件並保存,文件內容以下bash
export GOROOT=/usr/local/opt/go/libexec # GOPAT爲上面建立的目錄路徑 export GOPATH=/Users/deweixu/coding/Go/go_path export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
運行source .bash_profile
使配置的PATH
生效。ui
運行go env
查看安裝效果:debug
$ go env GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/deweixu/coding/Go/go_path" GORACE="" GOROOT="/usr/local/opt/go/libexec" GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64" CC="clang" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/q3/kxp92gk548z_y9pc1n3qsztw0000gn/T/go-build078494854=/tmp/go-build -gno-record-gcc-switches -fno-common" CXX="clang++" CGO_ENABLED="1"
enjoy golang
code