go-version
Display Go compiler version information
TLDR
Display version
Display the Go version used to build a specific executable file
SYNOPSIS
go version [-m] [buildID]
PARAMETERS
-m
Print main module path, version, and modinfo (if in module mode)
buildID
Optional argument: build ID from a binary; prints Go version used to build it
DESCRIPTION
The go version command, part of the Go programming language toolchain, prints the version of the installed Go compiler and runtime environment. Essential for developers, it confirms compatibility before compiling, testing, or deploying Go applications. Standard output format is go version goX.Y.Z os/architecture, e.g., go version go1.21.5 linux/amd64.
Without flags, it shows basic version details. The -m flag adds module information, including the main module's path, version, and source hash (in module mode), aiding debugging in Go modules workflows. Supplying a buildID argument (from binaries via tools like readelf or go tool objdump) reveals the exact Go version used to build that executable or object file.
Fast and lightweight, go version is commonly scripted in CI/CD pipelines, Dockerfiles, and setup checks to enforce version requirements. Available on Linux when Go is installed via official binaries, package managers like apt/snap, or built from source.
CAVEATS
Requires Go toolchain installed and in PATH. buildID must be valid (e.g., from 'go version -m binary'); otherwise, errors occur. Module info requires GO111MODULE=on or GOPATH-aware setup.
EXAMPLE OUTPUT
go version
go version go1.21.5 linux/amd64
go version -m
go version go1.21.5 linux/amd64
path example.com/myapp
mod example.com/myapp v1.0.0 h1:ABC123...
EXIT STATUS
Returns 0 on success, non-zero if invalid buildID or Go not found.
HISTORY
Introduced in Go 1.0 (2012, roots in 2009 preview). -m flag added in Go 1.11 (2018) with modules support. Enhanced for build IDs in later releases for binary introspection.


