go 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

go 命令安装:


-bash/zsh: go: command not found

# Windows (WSL2)
sudo apt-get update sudo apt-get install golang-bin

# Debian
apt-get install golang-bin

# Ubuntu
apt-get install golang-bin

# Alpine
apk add go

# Arch Linux
pacman -S go

# CentOS
yum install go

# Kali Linux
apt-get install golang-bin

# Fedora
dnf install golang-bin

# OS X
brew install go

# Raspbian
apt-get install golang-bin

# Dockerfile
 dockerfile.run/go

# Docker
docker run cmd.cat/go go

go 命令补充说明:


Go 是一个管理 Go 源代码的工具。可以帮助开发者在命令行中完成各种任务,例如编译、运行、测试、构建、格式化等。Go 命令具有简单、易用、高效等特点,可以提高开发效率和代码质量。同时,Go CLI 命令还提供了丰富的参数和选项,可以满足不同开发者的需求。总的来说,Go CLI 命令是 GO 语言开发中不可或缺的工具,可以帮助开发者更加便捷地进行开发和调试。

go 命令语法:


go <command> [arguments]

go 命令选项:


The commands are:

        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
        fix         update packages to use new APIs
        fmt         gofmt (reformat) package sources
        generate    generate Go files by processing source
        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
        test        test packages
        tool        run specified go tool
        version     print Go version
        vet         report likely mistakes in packages


Use "go help <command>" for more information about a command.

Additional help topics:

        buildconstraint build constraints
        buildmode       build modes
        c               calling between Go and C
        cache           build and test caching
        environment     environment variables
        filetype        file types
        go.mod          the go.mod file
        gopath          GOPATH environment variable
        gopath-get      legacy GOPATH go get
        goproxy         module proxy protocol
        importpath      import path syntax
        modules         modules, module versions, and more
        module-get      module-aware go get
        module-auth     module authentication using 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

Use "go help <topic>" for more information about that topic.

go 命令实例:


go 下载并安装由其导入路径指定的包:

go get package_path

go 编译并运行一个源文件(它必须包含一个 `main` 包):

go run file.go

go 将源文件编译成命名的可执行文件:

go build -o executable file.go

go 编译当前目录中的包、执行当前包的所有测试用例(文件必须以 _test.go 结尾):

go build

go test

go 编译安装当前包:

go install

go 在当前目录中初始化一个新模块:

go mod init module_name

go 命令扩展阅读:




go 命令评论