在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