本文档中所有shell命令基于mac OS 环境下进行。
安装 goctl
环境: macOS/Linux
$ GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/tal-tech/go-zero/tools/goctl
运行输出
go: found github.com/tal-tech/go-zero/tools/goctl in github.com/tal-tech/go-zero v1.0.22 go: downloading github.com/urfave/cli v1.22.4 go: downloading github.com/logrusorgru/aurora v2.0.3+incompatible go: downloading github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 go: downloading github.com/go-sql-driver/mysql v1.5.0 go: downloading github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d go: downloading github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 go: downloading github.com/spaolacci/murmur3 v1.1.0 go: downloading github.com/russross/blackfriday/v2 v2.0.1 go: downloading go.uber.org/automaxprocs v1.3.0 go: downloading github.com/shurcooL/sanitized_anchor_name v1.0.0 go: downloading github.com/emicklei/proto v1.9.0 go: downloading gopkg.in/yaml.v2 v2.2.8 go: github.com/go-sql-driver/mysql upgrade => v1.5.0 go: gopkg.in/yaml.v2 upgrade => v2.3.0 go: github.com/urfave/cli upgrade => v1.22.4 go: github.com/cpuguy83/go-md2man/v2 upgrade => v2.0.0 go: github.com/iancoleman/strcase upgrade => v0.1.2 go: downloading github.com/cpuguy83/go-md2man/v2 v2.0.0 go: downloading github.com/iancoleman/strcase v0.1.2 go: downloading gopkg.in/yaml.v2 v2.3.0
goctl 将被安装在 $GOPATH/bin
目录下
设置 GOPATH 并将 $GOPATH/bin
添加到环境变量 PATH 中
macOS/Linux :
export GOPATH=$(go env GOPATH) export PATH="$GOPATH/bin:$PATH"
让环境变量永久生效:
zsh:
echo '\nexport PATH="$GOPATH/bin:$PATH"' >> .zshrc source ~/.zshrc
bash:
echo '\nexport PATH="$GOPATH/bin:$PATH"' >> .bashrc source ~/.bashrc
验证安装
运行goctl -v
,如果结果输出包含goctl version xxx
字样则代表goctl安装成功。
goctl -v
输出结果
goctl version 20201021 darwin/amd64