使用Homebrew安裝配置golang環境

安裝Homebrew

Homebrew複製安裝命令,在控制檯運行完成安裝golang

安裝golnag

$ brew update && brew upgrade
$ brew install go

PATH配置

建立一個目錄做爲gopath,在目錄建立三個目錄binsrcpkgvim

$ 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 golangcode

相關文章
相關標籤/搜索