Using `go run` is useful during development. It provides a convenient developer experience like Python, Node.js, and other scripting environments that don't have a compilation step. It also helpfully prints the exit code if a program exits with an error.
However, once you're ready to build a standalone binary executable for distribution, use `go build`.
```
$ go build hello-world.go
```
By default, this produces an executable command named after the program, minus the `.go` extension on \*nix-based systems or replaced with `.exe` on Windows.
```
$ ls -lh hello-world*
-rwxr-xr-x 1 tony staff 2.1M Aug 25 11:08 hello-world
-rw-r--r-- 1 tony staff 109B Aug 24 14:52 hello-world.go
```
Run the compiled command:
```
$ ./hello-world
Hello, World!
```
To generate the compiled command with a specific name, use the `-o` flag.
```
$ go build -o hello hello-world.go
$ ls -lh hello*
-rwxr-xr-x 1 tony staff 2.1M Aug 25 21:34 hello
-rw-r--r-- 1 tony staff 109B Aug 24 14:52 hello-world.go
```
See:
- https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies
- https://go.dev/doc/tutorial/compile-install
---
Next: [[5. Command Arguments]]