Go build tools turn source code into an executable, and deployment tools take that executable and run it somewhere. go build, go install and go run belong to the first group, and they are part of the Go toolchain. Docker, Kubernetes, systemd, Terraform and a CI/CD system belong to the second group, and they are independent of Go.
Go makes the boundary easy to see: the build step produces a single statically linked binary, and deployment is about packaging, configuring, shipping and operating that file.
Build tools compile packages, resolve module dependencies and write an artifact. The commands you use most are these.
| Command | What it does |
|---|---|
go build | Compiles packages and writes an executable (or discards the result for libraries) |
go install | Builds and installs binaries into GOBIN, which defaults to $GOPATH/bin |
go run | Compiles to a temporary location and runs immediately |
go mod tidy | Adds missing and removes unused module requirements |
go vet and go test | Check and test the code before it is built into a release |
Go cross-compiles with two environment variables, and no extra toolchain is required for pure Go code.
CGO_ENABLED=0 produces a fully static binary, -trimpath removes local file paths for reproducible builds, and -s -w strips symbol and debug information to reduce size. You can also inject a version string with -ldflags "-X main.version=v1.2.3".
Deployment tools handle everything after the binary exists: packaging it, delivering it to an environment, supplying configuration and secrets, starting it, scaling it, rolling out new versions and rolling back. None of that is Go specific, so the same tools deploy services written in any language.
Common choices include:
A multi-stage Dockerfile keeps the compiler out of the final image.
Copying go.mod and go.sum first lets Docker cache the dependency download layer. The final image contains only the static binary, which is small and has a reduced attack surface. Pin the Go version to the one your go.mod requires.
Then a Kubernetes manifest runs it.
Use an immutable version tag or a digest rather than latest, so a deployment is reproducible and a rollback goes to a known image. Readiness probes tell Kubernetes when a new pod can receive traffic.
| Aspect | Build tools | Deployment tools |
|---|---|---|
| Goal | Produce a correct artifact | Run and operate that artifact |
| Input | Source code and modules | Binary or image plus configuration |
| Output | Executable or library | Running service in an environment |
| Examples | go build, go install, go mod | Docker, Kubernetes, systemd, Terraform |
| Go specific | Yes | No |
| Runs | On a developer machine or CI runner | In staging and production |
A typical pipeline runs go vet and go test ./..., then go build, then builds and pushes an image, and finally updates the deployment, either by applying manifests or by committing a new image tag to a GitOps repository. Keeping the build reproducible, and building once then promoting the same artifact through environments, avoids "works in staging" surprises.
No. go install only places a built binary on the local machine, usually for developer tools. Deploying means delivering and running it on target infrastructure.
No. You can copy the static binary to a server and run it under systemd. Containers help with consistent environments, orchestration and scaling.
It creates a static binary with no dependency on the system C library, so it runs in minimal images such as scratch or distroless. Use it only when your code and dependencies do not need cgo.
No. The Go toolchain stops at building, testing and installing. Deployment relies on general-purpose tools.
Build tools such as go build and go install compile your code into an artifact, and cross-compilation flags let you target any platform. Deployment tools such as Docker, Kubernetes, systemd and CI/CD pipelines package, ship, configure and run that artifact. Build a static binary, wrap it in a small image, tag releases immutably and let automation handle the rollout.