Amblem
Furkan Baytekin

Using Makefile in Go Projects (The Practical Way)

Go Makefile tutorial with practical examples

Using Makefile in Go Projects (The Practical Way)
4
3 minutes

Go already gives you a solid toolchain, but once a project grows, repeating commands gets old fast. A simple Makefile gives you standardized commands, less typing, and zero dependencies.

This post shows a minimal, useful Makefile for Go projects:


Project Structure

tree
. ├── cmd/ │ └── projectname/ │ └── main.go ├── bin/ ├── air.toml ├── go.mod ├── Makefile

Why Use Makefile with Go?

Go stays simple, Make just glues things together.


The Makefile

makefile
APP_NAME := projectname BIN_DIR := bin BIN_PATH := $(BIN_DIR)/$(APP_NAME) .PHONY: build run dev clean help ## build: Build the Go binary build: @mkdir -p $(BIN_DIR) go build -o $(BIN_PATH) ./cmd/$(APP_NAME) ## run: Run the built binary run: build @./$(BIN_PATH) ## dev: Run with live reload using air dev: @air ## clean: Remove build artifacts clean: @rm -rf $(BIN_DIR) ## help: Show available commands help: @echo "" @echo "Available commands:" @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ | awk 'BEGIN {FS = ":.*?## "}; {printf " %-10s %s\n", $$1, $$2}'

make build

bash
make build

This keeps your repo clean and binaries out of the way.


make run

bash
make run

Simple dependency chain:

makefile
run: build

make dev (Live Reload)

Uses Air for hot reload.

bash
make dev

Make sure Air is installed:

bash
go install github.com/air-verse/air@latest

And you have an air.toml:

toml
root = "." tmp_dir = "tmp" [build] cmd = "go build -o bin/projectname ./cmd/projectname" bin = "bin/projectname"

make clean

bash
make clean

Deletes: bin/

Useful for:


make help

bash
make help

Outputs something like:

bash
Available commands: build Build the Go binary run Run the built binary dev Run with live reload using air clean Remove build artifacts help Show available commands

This works because of the ## comments — small trick, big win.


Final Notes

For Go projects, this setup hits the sweet spot: simple, readable, and production-safe.

Done.

Album of the blog:

Suggested Blog Posts