The Go Compiler
Go is a compiled language. This means your source code is converted into machine code (binary) before it is executed.
Two Ways to Run Go
| Command | Action | Best for... |
|---|---|---|
go run |
Compiles to a temp folder and runs immediately. | Development and testing. |
go build |
Compiles to a permanent executable binary. | Production and shipping apps. |
Building for Production
When you run go build, Go creates a self-contained binary. This binary includes everything it needs to run—no need to install Go on the server!
Cross-Compilation
One of Go's best features is the ability to build binaries for other operating systems from your current machine.
Why is the Go Compiler special?
- Fast: Even large projects compile in seconds.
- Static Binaries: By default, Go binaries don't depend on external libraries (like
libc). - Optimization: The compiler automatically removes unused code (dead code elimination) to keep binaries small and fast.