Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 31 of 60 · Go

Building and Publishing a Go Binary

Duration: 20 minutes

Building Executables

This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.

go build compiles a binary for the host OS/architecture.

$ go build -o myapp ./cmd/myapp

Cross‑compilation

# Build Linux binary on macOS
env GOOS=linux GOARCH=amd64 go build -o myapp-linux

Distributing binaries

  • Upload to GitHub Releases.
  • Use goreleaser for automated builds.
$ go install github.com/goreleaser/goreleaser/v2@latest
$ goreleaser release --snapshot --skip-publish

Containerizing with Docker

FROM golang:1.22-alpine AS builder
WORKDIR /src
COPY . .
RUN go build -o /app ./cmd/app

FROM alpine:latest
COPY --from=builder /app /app
ENTRYPOINT ["/app"]

Info

Static linking (CGO_ENABLED=0) produces lean containers.

Previous: Tooling – `go fmt`, `go vet`, `golint`, and `staticcheck`Next: Profiling Go Applications with pprof