go run
The go subcommand that compiles a program to a temporary place and runs it straight away, leaving no binary behind.
In more detail
go run is for the edit-and-check loop while you are writing code. Words after the package are passed to your program as arguments, not to the compiler. Use go build when you need a file to ship.
Examples
go run .go run . more arguments # extra words reach os.ArgsRelated terms
- go build — The go subcommand that compiles a package and its dependencies into an executable file and prints nothing when it succeeds.
- go install — The go subcommand that compiles a program and places the binary in the bin folder under your Go path, so it works as a command anywhere.
- os.Args — The slice of strings holding the words a Go program was started with, where os.Args[0] is the program itself.
Taught in
- Go Workspaces and Modules — Concurrent Systems Programming with Go
- Your First Program and go run — Concurrent Systems Programming with Go