← BYTES
Go·Starter·Ref: 10.1.7

What is the practical difference between `go run main.go` and `go build main.go`?

Have a question about this video? Mention reference 10.1.7 when you contact us.

a.They are exactly identical commands with different names
b.go run is for testing, go build is for production, and they use different compilers
c.go build only works for multi-file projects, go run only works for single files
d.go run compiles and immediately executes the program without leaving a binary on disk (by default); go build only compiles, producing a binary file you then run separately
go build compiles the source into an executable binary left on disk for you to run and distribute later. go run does the same compilation step but then immediately executes the resulting binary itself (typically from a temporary location) and does not leave a binary behind -- convenient for quick iteration, not for shipping.

Find this on YouTube & Instagram

Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:

#BYTES#BYTES1017#Go