Set variables at link time with -ldflags -X.
Section: Build Flags
Inject version info
bash
bash
go build -ldflags="-X main.version=1.2.3" .Explanation
Set variables at link time with -ldflags -X. Useful in Go CLI workflows.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Build Flags