Mac下golang环境安装以及新手入门
环境安装
mac 环境 首先安装brew
brew install go
执行完命令后,如下显示:
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/services).
No changes to formulae.
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/go-1.11.2.m
######################################################################## 100.0%
==> Pouring go-1.11.2.mojave.bottle.tar.gz
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall go`
==> Caveats
A valid GOPATH is required to use the `go get` command.
If $GOPATH is not specified, $HOME/go will be used by default:
https://golang.org/doc/code.html#GOPATH
You may wish to add the GOROOT-based install location to your PATH:
export PATH=$PATH:/usr/local/opt/go/libexec/bin
==> Summary
🍺 /usr/local/Cellar/go/1.11.2: 9,282 files, 404MB
需要设置GOPATH和GOROOT的环境变量,以及设置PATH.
环境变量配置
通过go env查看go的详细信息
go env
需要设置的环境变量包括:GOPATH ,GOBIN 以及把GOBIN加入到PATH中,GOROOT变量默认已经设置好。
如果需要修改默认的环境变量配置修改 vim ~/.bash_profile 或者 vim ~/.zshrc
#GOROOT
# CentOS 中如下设置 GOROOT,看你安装的路径
# export GOROOT=/usr/local/go
# Mac OS 中通过命令行工具brew安装如下配置 GOROOT
export GOROOT=/usr/local/opt/go/libexec
#GOPATH ro