go install: Usage, Options & Common CI Errors
Build and install a Go binary to your bin directory.
go install compiles a main package and installs the executable into GOBIN (or $GOPATH/bin, default ~/go/bin). With a package@version argument it installs a tool without touching your go.mod.
What it does
Builds the named main package and places the binary in the install directory. The pkg@version form (Go 1.16+) installs in module-aware mode independent of the current module.
Common usage
go install ./cmd/app # install from this module
go install golang.org/x/tools/cmd/stringer@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1Common CI error: installed tool not on PATH
go install puts the binary in ~/go/bin but a later CI step reports "command not found" because that directory is not on PATH. Fix on GitHub Actions: echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH". If you omit @version outside a module you get "go install: version is required" - add it.
Options
| Form | Effect |
|---|---|
| ./cmd/x | Install from the current module |
| pkg@latest | Install a tool at latest |
| pkg@v1.2.3 | Install a pinned tool version |
| GOBIN env | Override the install directory |