$linuxjunkies
>

go(1)

Go is a compiled programming language designed for building fast, reliable, and efficient software.

UbuntuDebianFedoraArch

Synopsis

go <command> [arguments]

Description

Go (golang) is an open-source compiled language created by Google. It combines the performance of compiled languages with the simplicity of dynamic languages, featuring built-in concurrency, garbage collection, and cross-platform compilation.

The go command is the main toolchain for compiling, testing, installing, and managing Go programs and dependencies. It works with Go modules for dependency management and can build binaries for multiple operating systems and architectures.

Common options

FlagWhat it does
go buildCompile packages and dependencies into an executable binary
go runCompile and run Go program without creating a permanent binary
go testExecute tests in Go packages
go installCompile and install packages to $GOPATH/bin or $GOBIN
-vVerbose output; print names of compiled packages
-o FILEWrite output to FILE instead of default location
go mod tidyAdd missing and remove unused module dependencies
go fmtReformat source code to standard Go style
-raceEnable race condition detector (build/test)
go getDownload and install packages and dependencies

Examples

Compile and execute main.go immediately without creating a binary

go run main.go

Compile current package and save executable as 'myapp'

go build -o myapp

Run all tests in current module and all subdirectories

go test ./...

Download, compile, and install a package from GitHub

go install github.com/user/package@latest

Format all Go source files in current module to standard style

go fmt ./...

Download modules to local cache without building

go mod download

Compile with verbose output and race detector enabled

go build -v -race

Run benchmarks with memory allocation statistics

go test -bench=. -benchmem

Related commands