命令 | 解释 | 中文 |
---|---|---|
go help | help | 帮助 |
bug | start a bug report | 开始错误报告 |
build | compile packages and dependencies | 编译包和依赖项 |
clean | remove object files and cached files | 删除对象文件和缓存文件 |
doc | show documentation for package or symbol | 显示包或符号的文档 |
env | print Go environment information | 打印Go环境信息 |
fix | update packages to use new APIs | 更新包以使用新的API |
fmt | gofmt (reformat) package sources | gofmt(重新格式化)包源 |
generate | generate Go files by processing source | 按处理源生成Go文件 |
get | add dependencies to current module and install them | 将依赖项添加到当前模块并安装它们 |
install | compile and install packages and dependencies | 编译和安装软件包和依赖项 |
list | list packages or modules | 列出包或模块 |
mod | module maintenance | 模块维护 |
work | workspace maintenance | 工作区维护 |
run | compile and run Go program | 编译并运行Go程序 |
test | test packages | 测试包 |
tool | run specified go tool | 运行指定的go工具 |
version | print Go version | 打印Go版本 |
vet | report likely mistakes in packages | 报告包中可能的错误 |
buildconstraints | build constraints | 生成约束 |
buildmode | build modes | 构建模式 |
c | calling between Go and C | 在Go和C之间调用 |
cache | build and test caching | 生成和测试缓存 |
environment | environment variables | 环境变量 |
filetype | file types | 文件类型 |
go.mod | the go.mod file | go.mod文件 |
gopath | GOPATH environment variable | GOPATH环境变量 |
gopath-get | legacy GOPATH go get | 传统GOPATH go get |
goproxy | module proxy protocol | 模块代理协议 |
importpath | import path syntax | 导入路径语法 |
modules | modules, module versions, and more | 模块、模块版本等 |
module-get | module-aware go get | 模块感知go get |
module-auth | module authentication using go.sum | 使用go进行模块身份验证go.sum |
packages | package lists and patterns | 包列表和模式 |
private | configuration for downloading non-public code | 下载非公开代码的配置 |
testflag | testing flags | 测试标志 |
testfunc | testing functions | 测试功能 |
vcs | controlling version control with GOVCS | 使用GOVCS控制版本控制 |
vim ~/.bash_profile
配置以下环境变量到文件中
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
配置完输入:wq
输入以下命令使环境变量生效
source ~/.bash_profile
测试版本
go version
出现以下信息
go version go1.18.3 darwin/amd64
写一个hello world
vim test.go
package main
import "fmt"
func main(){
fmt.Println("hello world")
}