(1)按顺序依次在控制台执行(之前学Beego的时候,一直拉不下来项目,最后发现应该是第一步的问题)
1.$ echo "export GO111MODULE=on" >> ~/.bash_profile
2.$ echo "export GOPROXY=https://goproxy.cn" >> ~/.bash_profile
3.$ source ~/.bash_profile
(2) 配置环境变量, 最后两个是在输入完(1)步的时候自动写入的,所以第(1)步很重要
#GOROOT
export GOROOT=/usr/local/go
#GOPATH
export GOPATH=/Users/canyonwan/go
#GOROOT bin
export PATH=$PATH:$GOROOT/bin
#GOPATH bin
export PATH=$PATH:$GOPATH/bin
#GO Modules 功能
export GO111MODULE=on
#GO Proxy 以下两个代理写一个就行(七牛云和阿里云),
export GOPROXY=https://goproxy.cn
export GOPROXY=https://mirrors.aliyun.com/goproxy/
但是注意设置上国内的代理后,go get下来的项目会下载/Users/canyonwan/go/pkg/mod目录下
(3) 执行完上述命令后, 执行以下命令
$ go env