LinuxCommandLibrary

go-version

Display Go compiler version information

TLDR

Display version

$ go version
copy

Display the Go version used to build a specific executable file
$ go version [path/to/executable]
copy

SYNOPSIS

go version [-m] [-v]

PARAMETERS

-m
    Prints module information along with the Go version. When executed inside a Go module directory, it lists the main module and its dependencies. If not in a module, it behaves similarly to go version.

-v
    Prints more verbose details about the Go version, potentially including the exact Git commit hash from which the Go toolchain was built, and additional build information.

DESCRIPTION

The
go version command is a fundamental subcommand of the
Go toolchain, providing crucial information about the installed Go compiler and runtime. Its primary function is to display the Go version number, the operating system, and the hardware architecture for which the Go toolchain was built. For instance, it might output
go version go1.22.4 linux/amd64, clearly indicating the Go release and the target platform.

This command is indispensable for developers to quickly verify their Go environment, ensuring they are using the correct version for their projects. It's also vital for debugging compatibility issues when collaborating with others or deploying applications to different servers. System administrators and automated build systems heavily rely on
go version to confirm the presence and specifics of the Go installation, making it a cornerstone for consistent development and deployment workflows, especially within
CI/CD pipelines to enforce version control and avoid unexpected build failures.

CAVEATS

This is not a standalone
linux command named 'go-version'. Instead, it is a subcommand of the main
go command:
go version. It requires the Go toolchain to be installed and accessible via the system's
PATH. The exact output can vary slightly depending on the Go version and whether it was built from an official release or a custom source.

TYPICAL OUTPUT

A standard output for
go version looks like:
go version go1.22.4 linux/amd64. This indicates the Go release, the operating system, and the architecture for which it was compiled.

USAGE CONTEXT

This command can be executed from any directory in your terminal, provided the
Go toolchain is properly installed and configured in your system's
PATH environment variable. It does not require to be run within a Go project directory unless using the
-m flag for module information.

HISTORY

The
go version command has been an integral part of the Go toolchain since its inception, serving as the primary method to identify the installed Go compiler and runtime. Its consistent output format has made it highly reliable for scripting and automation purposes, particularly in continuous integration and deployment workflows to ensure specific Go versions are used for builds.

SEE ALSO

go(1), go env(1), go build(1), go install(1)

Copied to clipboard