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
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Building and Publishing a G | Go Programming Bootcamp lesson | BraveProgrammer
  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 31 of 60

·Go

Building and Publishing a Go Binary

20 minutes

Course progress52%

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.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from Go Programming BootcampBrowse activities
Previous lessonTooling – `go fmt`, `go vet`, `golint`, and `staticcheck`Continue to lesson 32Profiling Go Applications with pprofBack to Go Programming Bootcamp curriculum