LinuxCommandLibrary

go-get

Download and install Go packages

TLDR

Add a specified package to go.mod in module-mode or install the package in GOPATH-mode

$ go get [example.com/pkg]
copy

Modify the package with a given version in module-aware mode
$ go get [example.com/pkg]@[v1.2.3]
copy

Remove a specified package
$ go get [example.com/pkg]@[none]
copy

SYNOPSIS

go get [-d] [-f] [-insecure] [-t] [-u] [-v] [-x] [-mod=mod] [packages]

PARAMETERS

-d
    Download source only; skip build/install.

-f
    Fetch ignoring dependency graph or local state.

-insecure
    Allow HTTP or insecure repo access.

-t
    Include test dependencies.

-u
    Update packages and deps to latest compatible.

-v
    Enable verbose progress messages.

-x
    Print executed commands.

-mod=mod
    Module download mode: auto|readonly|vendor|off.

DESCRIPTION

go get is a core command in the Go toolchain for fetching, building, and installing packages and dependencies from remote repositories, typically Git-hosted. It resolves import paths (e.g., github.com/user/repo), downloads source code, and integrates it into your workspace or module.

Before Go modules (pre-1.11), it populated the GOPATH with packages, updating go.list implicitly. Since modules became standard (Go 1.11+), go get modifies go.mod and go.sum, adding minimal versions required. For binaries, it installs to $GOBIN or $GOPATH/bin.

Usage example: go get github.com/spf13/cobra adds a dependency; go get -u ./... updates everything. With modules, prefer explicit versioning like go get [email protected]. It's essential for toolchains but pair with go mod tidy for hygiene.

Verbosity and control via flags enable precise workflows, from dry-runs to insecure fetches.

CAVEATS

Modifies go.mod/go.sum; run go mod tidy after. GOPATH mode disabled by default (GO111MODULE=off needed). Not for production deploys.

BINARY INSTALLATION

Use go get pkg@latest to install tools into $GOBIN; respects go env GOBIN.

VERSION SELECTION

Specify @v1.2.3, @latest, or @master for precise control; defaults to latest tagged.

HISTORY

Introduced in Go 1.0 for GOPATH management. Evolved with modules (Go 1.11: go.mod integration), vgo experiments. Go 1.17 deprecated GOPATH mode; 1.18+ defaults to modules-only.

SEE ALSO

go install(1), go mod(1), go list(1), git(1)

Copied to clipboard