在MAC下安装Go环境和beego
原创
©著作权归作者所有:来自51CTO博客作者行走的皮卡丘的原创作品,请联系作者获取转载授权,否则将追究法律责任
在MAC下安装Go环境和beego
MAC安装go的环境
下载go给出一个下载地址:
go下载链接
mac电脑使用这个版本的就好了
下载之后我们按照步骤安装即可
测试
配置环境变量
创建GOPATH
系统自己建了一个go的目录,在我们的用户目录下
修改环境变量配置文件
添加配置
export GOPATH=${HOME}/go
export PATH=${PATH}:${GOPATH}/bin
应用配置文件
[Go 1.13 and above (RECOMMENDED)](https://goproxy.cn/#Go 1.13 and above (RECOMMENDED))
Open your terminal and execute
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
done.
[macOS or Linux](https://goproxy.cn/#macOS or Linux)
Open your terminal and execute
export GO111MODULE=on
export GOPROXY=https://goproxy.cn
or
echo "export GO111MODULE=on" >> ~/.profile
echo "export GOPROXY=https://goproxy.cn" >> ~/.profile
source
done.
Windows
Open your terminal and execute
C:\> $env:GO111MODULE = "on"
C:\> $env:GOPROXY = "https://goproxy.cn"
or
1. Open the Start Search, type in "env"
2. Choose the "Edit the system environment variables"
3. Click the "Environment Variables…" button
4. Under the "User variables for <YOUR_USERNAME>" section (the upper half)
5. Click the "New..." button
6. Choose the "Variable name" input bar, type in "GO111MODULE"
7. Choose the "Variable value" input bar, type in "on"
8. Click the "OK" button
9. Click the "New..." button
10. Choose the "Variable name" input bar, type in "GOPROXY"
11. Choose the "Variable value" input bar, type in "https://goproxy.cn"
12. Click the "OK" button
done.
如果您使用的 Go 版本是 1.13 及以上 (推荐)
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.io,direct
# 设置不走 proxy 的私有仓库,多个用逗号相隔(可选)
go env -w GOPRIVATE=*.corp.example.com
# 设置不走 proxy 的私有组织(可选)
go env -w GOPRIVATE=example.com/org_name
设置完上面几个环境变量后,您的 go
命令将从公共代理镜像中快速拉取您所需的依赖代码了。私有库的支持请看这里。
如果您使用的 Go 版本是 1.12 及以下
Bash (Linux or macOS)
# 启用 Go Modules 功能
export GO111MODULE=on
# 配置 GOPROXY 环境变量
export GOPROXY=https://goproxy.io
或者,根据文档可以把上面的命令写到.profile
或.bash_profile
文件中长期生效。
PowerShell (Windows)
# 启用 Go Modules 功能
env:GO111MODULE="on"
# 配置 GOPROXY 环境变量
env:GOPROXY="https://goproxy.io"
现在,当你构建或运行你的应用时,Go 将会通过 goproxy.io 获取依赖。更多信息请查看 使用指引。
安装beego
go get github.com/astaxie/beego
输入这个命令之后感觉等待了一万年
解决go get 很慢问题
解决这个问题,打开hosts文件,加上这两段
192.30.253.112 github.com
151.101.185.194 github.global.ssl.fastly.net
安装bee
go get github.com/beego/bee
测试