go-install
Install Go packages and dependencies
TLDR
Compile and install the current package
Compile and install a specific local package
Install the latest version of a program, ignoring go.mod in the current directory
Install a program at the version selected by go.mod in the current directory
SYNOPSIS
go install [build flags] [-i] [packages]
PARAMETERS
-i
Installs dependencies of packages before installing them. Deprecated since Go 1.17; use go mod download instead.
-a
Rebuilds packages even if up-to-date.
-gcflags
Arguments for the GC compiler (e.g., '-gcflags=all=-N -l').
-ldflags
Arguments for the linker (e.g., '-ldflags=-s -w').
-tags
Comma-separated build tags to consider satisfied.
-linkshared
Link against shared libraries previously created with -buildmode=shared.
-v
Print verbose output.
DESCRIPTION
The go install command compiles and installs Go packages, creating executables for main packages and library archives for others. Binaries are placed in $GOBIN (defaulting to $GOPATH/bin or $HOME/go/bin). In module-aware mode (default since Go 1.11), it resolves dependencies via go.mod and supports pseudo-versions like package@latest or package@v1.2.3.
It differs from go build by permanently installing the output, making it available system-wide. Dependencies are installed transitively unless in GOPATH mode without -i. Supports cross-compilation via GOOS and GOARCH. Ideal for tools and CLI apps, e.g., go install github.com/spf13/cobra@latest. Since Go 1.16, workspace and module caching optimize repeated installs. Does not update go.mod; use go get for that.
CAVEATS
Does not modify go.mod or add packages to import path permanently; binaries only. -i deprecated—prefer module tools. Fails if dependencies missing without -i in GOPATH mode. GOPATH mode legacy.
EXAMPLES
go install github.com/user/tool@latest
go install ./cmd/myapp
go install -ldflags='-s -w' .
ENVIRONMENT
GOPATH: Workspace root (legacy).
GOBIN: Binary install dir.
GOOS/GOARCH: Cross-compile targets.
HISTORY
Introduced in Go 1.0 for GOPATH workflow. Enhanced with modules in Go 1.11 for dependency resolution. Go 1.16 shifted default to module mode, standardized binary paths via GOBIN. Go 1.17 deprecated -i flag. Evolved for workspaces in Go 1.18+.
SEE ALSO
go build(1), go get(1), go mod(1), go list(1)


