go run executes code instantly, go build creates a local binary, and go install compiles and saves the binary to your global bin directory.
Use go run to execute code directly, go build to create a standalone binary, and go install to compile and save the binary to your GOPATH for global access.
# Execute immediately without saving a file
go run main.go
# Create a local executable named 'myapp'
go build -o myapp main.go
# Compile and install to GOPATH/bin for global use
go install ./cmd/myapp
Think of go run as a quick test drive that deletes the car afterward. go build is like manufacturing a car in your garage that you can keep and drive anytime. go install is like manufacturing the car and putting it on a public road so anyone can find and drive it.