Automate Repetitive Tasks with a Makefile

Turn the commands you type for every project — install, test, build, clean — into one-word make targets.

beginner10 minmacos · windows · linuxUpdated August 2026
#makefile#automation#productivity

Requirements

  • Terminal access

Choose your platform

0/3 steps · 0%
01

Confirm make is installed

bash
$ make --version

Note

macOS ships make with the Xcode Command Line Tools. If it's missing, run xcode-select --install.

02

Write a Makefile

Makefile
.PHONY: install test build clean
install:
npm install
test:
npm test
build:
npm run build
clean:
rm -rf node_modules dist

Important

Makefiles require tabs, not spaces, to indent recipe lines. An editor that converts tabs to spaces will silently break every target.

03

Run a target

bash
$ make install
$ make test

Success

Anyone on the project can now run make test instead of remembering the underlying command.

Troubleshooting

A recipe line under a target uses spaces instead of a literal tab character.

Re-indent the failing line with a single tab. Most editors can be configured to insert a real tab specifically for Makefiles.