Installing GNU Make

Install GNU Make on Linux, macOS and Windows, understand why macOS still ships Make 3.81, and set up your editor so recipe lines keep their TAB characters.

By The Dark DebuggerUpdated 19 min read

This article gets a working GNU Make onto your machine, checks that it's a version recent enough for the rest of the path, and sets up your editor so it stops turning the TABs in your Makefiles into spaces. It assumes you've read Introduction to Make and can open a terminal. The articles that follow also compile small C programs, so we'll install a C compiler alongside Make where it's cheap to do so.

Why the details matter

Installing Make is usually one command. The trouble comes later, and it comes in three flavours:

  • A Makefile that works on your Linux laptop fails on a colleague's Mac, because macOS ships a version of GNU Make from 2006.
  • A Makefile that looks perfect fails with missing separator, because your editor quietly inserted spaces where Make requires a TAB.
  • On Windows, a recipe like rm -f build/*.o fails, because native Make ran it through cmd.exe instead of a Unix shell.

We'll deal with all three here, so you only lose time to them once.

Check what you already have

Run:

make --version
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

That's Ubuntu 24.04's GNU Make. What the first line tells you:

First line saysWhat you haveWhat to do
GNU Make 4.xA current GNU MakeNothing. Skip to editor setup
GNU Make 3.81macOS's bundled Make (or an ancient Windows port)Fine for basics; install a 4.x for the full path (macOS)
No GNU Make line at allProbably BSD make (FreeBSD, OpenBSD, NetBSD)Install the GNU Make package; it runs as gmake
command not foundNo Make at allInstall it below

On a fresh Ubuntu system without Make, typing make prints a hint from Ubuntu's command-not-found helper. I reproduced it by calling that helper directly:

/usr/lib/command-not-found make
Command 'make' not found, but can be installed with:
sudo apt install make        # version 4.3-4.1build1, or
sudo apt install make-guile  # version 4.3-4.1build1

make-guile is the same GNU Make built with the GNU Guile extension language. You want plain make. The version number in that hint comes from a cached database and can lag behind; apt installs whatever the archive currently has.

Linux

Debian, Ubuntu, and Ubuntu on WSL

sudo apt update
sudo apt install build-essential

build-essential is a meta-package: it pulls in Make plus the C toolchain that the C examples in this path need. You can see exactly what it depends on without installing anything:

apt-cache depends build-essential
build-essential
 |Depends: libc6-dev
  Depends: <libc-dev>
    libc6-dev
  Depends: gcc
  Depends: g++
  Depends: make
    make-guile
  Depends: dpkg-dev

If you only want Make (say, as a task runner on a server), sudo apt install make is enough. To see which version you'd get before installing:

apt-cache policy make
make:
  Installed: (none)
  Candidate: 4.3-4.1build2
  Version table:
     4.3-4.1build2 500
        500 http://archive.ubuntu.com/ubuntu noble/main amd64 Packages

GNU Make 4.3 is what Ubuntu 24.04 ships, and it's what every example in this path was tested with.

Fedora, RHEL, Rocky and AlmaLinux

sudo dnf install make gcc

Arch Linux

sudo pacman -S make

Or sudo pacman -S base-devel for the whole toolchain, which most AUR packages expect anyway.

Alpine (common in containers)

apk add make

Alpine's BusyBox base has no make. For compiling C as well, apk add build-base brings in Make, GCC and the C library headers in one go.

macOS

Apple's Command Line Tools include Make:

xcode-select --install

After that, make --version reports GNU Make 3.81, a release from April 2006. Apple stopped updating it because GNU Make 3.82 and later are licensed under GPLv3, which Apple doesn't ship. That's the same reason macOS's /bin/bash is stuck at 3.2.

3.81 runs ordinary Makefiles, and the first few articles of this path work on it. But a lot has been added since. These are the features you'll meet in this path that 3.81 lacks, with the GNU Make version that introduced each (from the release notes):

FeatureSince
.ONESHELL (run a whole recipe in one shell)3.82
.RECIPEPREFIX (use a character other than TAB)3.82
undefine and the private modifier3.82
Pattern rules preferring the most specific (shortest-stem) match3.82
--output-sync / -O for readable parallel output, and --trace4.0
!= and ::= assignment, and the $(file ...) function4.0
.SHELLSTATUS (exit status of $(shell ...))4.2
Grouped targets (a b &: ...) and .EXTRA_PREREQS4.3

To get a current GNU Make, install it with Homebrew:

brew install make

Homebrew installs it as gmake, so it doesn't shadow Apple's /usr/bin/make. You can either type gmake, or put Homebrew's unprefixed copy first in your PATH by adding this line to ~/.zshrc:

export PATH="$(brew --prefix)/opt/make/libexec/gnubin:$PATH"

Open a new terminal and make --version should report Homebrew's GNU Make 4.x. My recommendation: do the PATH change on your own machine, but don't assume your teammates have. If a project needs 4.x features, have the Makefile check for them. The doctor target below shows one way.

Windows

Make was built for Unix, and the least painful way to use it on Windows is to give it Unix. WSL runs a real Ubuntu next to Windows. From an administrator PowerShell:

wsl --install

After a reboot, open "Ubuntu" from the Start menu, create your Linux user, and install the toolchain exactly as on Linux:

sudo apt update
sudo apt install build-essential

Keep your projects inside the Linux filesystem (~/projects/...), not under /mnt/c/.... Files on the Windows drive are much slower to access from WSL, and builds touch a lot of files.

Native Windows builds of GNU Make

If you need make in PowerShell or Git Bash without WSL, there are packages. I queried them on a Windows 11 machine without installing anything:

winget show --id ezwinports.make --exact
Found ezwinports: make [ezwinports.make]
Version: 4.4.1
Publisher: ezwinports
[…]
License: GPL-3.0
winget show --id GnuWin32.Make --exact
Found GnuWin32: Make [GnuWin32.Make]
Version: 3.81
[…]
choco search make --exact --limit-output
make|4.4.1

So winget install ezwinports.make or choco install make gives you GNU Make 4.4.1. Avoid the GnuWin32.Make package: it's 3.81, the same 2006 release macOS ships. MSYS2 users can run pacman -S make in the MSYS2 shell. Git for Windows (Git Bash) doesn't include Make at all.

The catch with native Make is the shell. If GNU Make finds an sh.exe on your PATH (from Git Bash or MSYS2), it runs recipes with it. If it doesn't, it falls back to cmd.exe. Then rm -f, mkdir -p, cp and / path separators stop working, and so do most Makefiles you find online. If you go native, run Make from Git Bash or MSYS2, not from plain cmd.exe.

Checking the version and features

For scripts and bug reports, the first line is usually all you need:

make -v | head -n 1
GNU Make 4.3

Make also exposes its own version as the variable MAKE_VERSION. You can print it without creating a Makefile, because -f - tells Make to read the Makefile from standard input:

echo 'all: ; @echo $(MAKE_VERSION)' | make -f -
4.3

Two things in that one-liner are worth knowing. A recipe can follow a semicolon on the rule line itself, and then it needs no TAB. The @ stops Make from echoing the command before running it. Your First Makefile covers both.

.FEATURES lists the optional capabilities this build of Make supports. It's the reliable way for a Makefile to check for something, rather than parsing version numbers:

echo 'all: ; @echo $(.FEATURES)' | make -f -
target-specific order-only second-expansion else-if shortest-stem undefine oneshell nocomment grouped-target extra-prereqs archives jobserver output-sync check-symlink load

And SHELL tells you which shell runs your recipes. On Linux it's always /bin/sh unless the Makefile changes it. On Ubuntu that's dash, not Bash, which matters once you write Bash-only syntax in a recipe:

echo 'all: ; @echo $(SHELL)' | make -f -
/bin/sh

Verify with a two-line Makefile

Now a real Makefile. Create it with printf, because \t in a printf format is a guaranteed TAB character, whatever your editor is set to do:

mkdir make-check && cd make-check
printf 'hello:\n\techo "GNU Make $(MAKE_VERSION) is working"\n' > Makefile
cat -A Makefile
make
hello:$
^Iecho "GNU Make $(MAKE_VERSION) is working"$
echo "GNU Make 4.3 is working"
GNU Make 4.3 is working

cat -A shows the TAB as ^I and each line end as $. Make printed the command (with $(MAKE_VERSION) already expanded) and then ran it.

To list recipe lines that really do start with a TAB, grep -P understands \t:

grep -nP '^\t' Makefile
2:	echo "GNU Make $(MAKE_VERSION) is working"

Set up your editor so TABs survive

Make identifies recipe lines by a leading TAB. Most editors are configured to insert spaces when you press Tab, because that's what most languages want. The fix is a per-filetype setting.

Vim

Vim ships with a filetype plugin for Makefiles that switches tab expansion off. It only runs if filetype plugins are enabled. To check, I gave Vim two minimal vimrc files that both say set expandtab (insert spaces everywhere), and pressed Tab on a new line in a Makefile with each.

Without filetype plugins:

set expandtab tabstop=4 shiftwidth=4
build: main.c$
    gcc -o app main.c$

Four spaces: a broken Makefile. With filetype plugins enabled:

set expandtab tabstop=4 shiftwidth=4
filetype plugin indent on
build: main.c$
^I^Igcc -o app main.c$

Real TABs, and two of them. The Makefile indent plugin had already indented the new line after a rule with one TAB, and my keypress added a second. In practice you just press Enter after the rule line and start typing. So the only line you need in your ~/.vimrc is filetype plugin indent on. Most distributions' default vimrc already has it. To see what Vim decided for the current buffer, open a Makefile and run :verbose setlocal expandtab?:

noexpandtab
	Last set from /usr/share/vim/vim91/ftplugin/make.vim line 16

Vim detects Makefile, GNUmakefile and *.mk files as Makefiles. A name like rules.make isn't detected. For those, add # vim: set ft=make : as the last line, or run :set ft=make. :set list shows TABs on screen (as ^I by default). Configuring Vim covers vimrc files and filetype settings in depth.

VS Code

VS Code recognises Makefiles and its built-in Makefile support defaults to TABs. A user or workspace setting can still override that, so it's worth pinning it. Open the command palette, run "Preferences: Open User Settings (JSON)", and add:

{
  "[makefile]": {
    "editor.insertSpaces": false,
    "editor.detectIndentation": false,
    "editor.tabSize": 8,
    "editor.renderWhitespace": "boundary"
  }
}

detectIndentation: false stops VS Code from "detecting" spaces in a Makefile that someone already broke and then carrying on with spaces. renderWhitespace draws a small arrow for each TAB so you can see them. If a file already has space-indented recipes, run "Convert Indentation to Tabs" from the command palette. (I validated this JSON with jq; the settings themselves weren't exercised in VS Code for this article.)

EditorConfig

If your team uses an .editorconfig file that sets indent_style = space for [*], it will override both editors' Makefile defaults. Add an exception:

[{Makefile,GNUmakefile,*.mk}]
indent_style = tab

The escape hatch you probably shouldn't use

Since 3.82, GNU Make lets you pick a different recipe prefix with .RECIPEPREFIX:

.RECIPEPREFIX = >
hello:
> echo "recipe lines start with > here"
make
echo "recipe lines start with > here"
recipe lines start with > here

It works, but every other reader of your Makefile, every syntax highlighter, and macOS's 3.81 will be confused. Fix the editor instead.

Where you'll use this

Getting the toolchain right is a team problem as much as a personal one. New contributors clone a repository, run make, and get a confusing error from a missing tool or an old Make. A common fix is a doctor target (some projects call it check-tools) that checks the prerequisites and says exactly what to install:

.PHONY: doctor
 
doctor:
	@echo "make     $(MAKE_VERSION)"
	@case "$(MAKE_VERSION)" in 3.*) echo "error: GNU Make 4.0+ required (macOS: brew install make, then run gmake)"; exit 1;; esac
	@command -v gcc >/dev/null || { echo "error: gcc not found (Debian/Ubuntu: sudo apt install build-essential)"; exit 1; }
	@printf 'gcc      '; gcc -dumpfullversion
	@command -v python3 >/dev/null || { echo "error: python3 not found"; exit 1; }
	@printf 'python3  '; python3 -c 'import platform; print(platform.python_version())'
	@echo "all required tools found"

Make expands $(MAKE_VERSION) before the shell sees the line, so the case statement is really testing the running Make's version. Each recipe line runs only if the previous one succeeded, so the first exit 1 stops the target. On a machine before the C compiler was installed, it failed like this:

make doctor
make     4.3
error: gcc not found (Debian/Ubuntu: sudo apt install build-essential)
make: *** [Makefile:6: doctor] Error 1

After installing the compiler:

make doctor
make     4.3
gcc      13.3.0
python3  3.12.3
all required tools found

I don't have a Mac in the lab, but you can test the macOS branch anyway: a variable set on the command line overrides even Make's built-in ones (more on that in Variables):

make doctor MAKE_VERSION=3.81
make     3.81
error: GNU Make 4.0+ required (macOS: brew install make, then run gmake)
make: *** [Makefile:5: doctor] Error 1

Run the same target as the first step of a CI job and a broken build image fails in seconds with a readable message, not halfway through a compile.

Common mistakes

Spaces instead of a TAB

A Makefile typed in an editor that expands tabs:

make
Makefile:2: *** missing separator.  Stop.

Line 2 is the first recipe line. If every recipe line is indented with exactly four spaces, sed can convert them in one go (check the result, because it will also convert any non-recipe line that happens to start with four spaces):

sed -i 's/^    /\t/' Makefile
cat -A Makefile
make
build:$
^Imkdir -p out$
^Iecho done > out/status.txt$
mkdir -p out
echo done > out/status.txt

Then fix the editor setting so it doesn't happen again.

Windows line endings in scripts that Make runs

GNU Make itself copes with CRLF line endings. I fed it a Makefile saved with Windows line endings and it built normally. Scripts called from your recipes don't cope. A deploy.sh saved on Windows has #!/bin/sh\r as its first line, and Linux looks for an interpreter literally named sh\r:

make
./deploy.sh
make: ./deploy.sh: No such file or directory
make: *** [Makefile:2: deploy] Error 127

The "No such file" refers to the interpreter, not the script, which is why this one is so confusing. Exit status 127 means "command not found". Strip the carriage returns and it works:

sed -i 's/\r$//' deploy.sh
make
./deploy.sh
deploying

To stop Git on Windows from converting the files back, add *.sh text eol=lf to the repository's .gitattributes.

Following a 4.x tutorial on macOS's 3.81

There's no single error message for this one, which is what makes it nasty. A 4.x feature in 3.81 might be a syntax error, or it might be silently treated as something else. For example, GNU Make 4.0 added FILES!= ls *.c (run a command and store its output). According to the 4.0 release notes, older versions read that line as an ordinary assignment to a variable named FILES!, so $(FILES) is simply empty and nothing complains. If a Makefile behaves differently on a Mac than on Linux, check make --version before anything else.

Summary

  • make --version tells you what you have. Anything 4.x is fine for this path; 3.81 means macOS's bundled copy (or the ancient GnuWin32 port).
  • On Debian and Ubuntu, sudo apt install build-essential installs Make plus the C toolchain. Fedora uses dnf install make gcc, Arch pacman -S make, Alpine apk add make.
  • macOS is stuck on GNU Make 3.81 for licensing reasons. brew install make gives you 4.x as gmake, or as make once Homebrew's gnubin directory is first in your PATH.
  • On Windows, use WSL. Native ports (winget install ezwinports.make, choco install make) work, but they need a Unix sh.exe on PATH or recipes run under cmd.exe.
  • $(MAKE_VERSION), $(.FEATURES) and $(SHELL) describe the running Make. make -f - reads a Makefile from standard input for quick experiments.
  • Recipe lines need a real TAB. Verify with cat -A (^I) or grep -P '^\t'. In Vim, filetype plugin indent on is enough. In VS Code, pin "editor.insertSpaces": false for [makefile].
  • Make tolerates CRLF Makefiles, but CRLF shell scripts fail with a misleading No such file or directory and exit status 127.

Exercises

Exercise 1: Interrogate your Makeeasy

Without creating any files, print the version of Make you're running and the shell it uses for recipes, each on its own line.

Hint

Pipe a one-rule Makefile into make -f -. A recipe can follow a semicolon on the rule line, and a rule's recipe can have more than one command if you separate them with ; inside the shell command.

Show Solution
echo 'all: ; @echo $(MAKE_VERSION); echo $(SHELL)' | make -f -
4.3
/bin/sh

The whole recipe echo 4.3; echo /bin/sh is a single shell command line, so the @ at its start silences the echo for both parts.

Exercise 2: Prove the TAB is thereeasy

Create a Makefile with a version target that runs make --version | head -n 1. Use printf so the TAB is guaranteed. Show that the recipe line starts with a TAB using two different commands, then run the target.

Show Solution
printf 'version:\n\tmake --version | head -n 1\n' > Makefile
cat -A Makefile
grep -cP '^\t' Makefile
make version
version:$
^Imake --version | head -n 1$
1
make --version | head -n 1
GNU Make 4.3

cat -A shows the TAB as ^I. grep -cP '^\t' counts lines that start with a TAB, here the single recipe line.

Exercise 3: Repair a space-indented Makefilemedium

Someone pasted this Makefile from a web page, and the recipe lines arrived indented with four spaces. Create it exactly like this, confirm it fails, then repair it with one command and confirm that make builds out/status.txt.

printf 'build:\n    mkdir -p out\n    echo done > out/status.txt\n' > Makefile
Show Solution
make
sed -i 's/^    /\t/' Makefile
make
cat out/status.txt
Makefile:2: *** missing separator.  Stop.
mkdir -p out
echo done > out/status.txt
done

The sed expression replaces four leading spaces with a TAB on every line. That's safe here because only recipe lines are indented. On a bigger file, check the result with cat -A before committing it.

Exercise 4: Fix a script with Windows line endingsmedium

Recreate the CRLF problem and fix it: create deploy.sh with Windows line endings and a Makefile that runs it, observe the failure, then repair the script.

printf '#!/bin/sh\r\necho "deploying"\r\n' > deploy.sh
chmod +x deploy.sh
printf 'deploy:\n\t./deploy.sh\n' > Makefile
Show Solution
make
sed -i 's/\r$//' deploy.sh
make
./deploy.sh
make: ./deploy.sh: No such file or directory
make: *** [Makefile:2: deploy] Error 127
./deploy.sh
deploying

file deploy.sh before the fix would report with CRLF line terminators. The sed command deletes the carriage return at the end of each line.

Exercise 5: Write a version guardhard

Write a Makefile whose default target, check-make, prints GNU Make <version> OK on Make 4.x and fails with a clear message on 3.x. Test both paths on the same machine.

Hint

$(MAKE_VERSION) is expanded by Make before the shell runs the recipe, so a shell case statement can test it. Setting MAKE_VERSION=3.81 on the command line lets you test the failure path.

Show Solution
check-make:
	@case "$(MAKE_VERSION)" in 3.*) echo "GNU Make 4.0+ required, found $(MAKE_VERSION)"; exit 1;; esac
	@echo "GNU Make $(MAKE_VERSION) OK"
make
make MAKE_VERSION=3.81
GNU Make 4.3 OK
GNU Make 4.0+ required, found 3.81
make: *** [Makefile:2: check-make] Error 1

The exit 1 makes the first recipe line fail, so Make stops before the second line and exits with an error. That's exactly what you want at the top of a CI job.


Tested with: GNU Make 4.3 and Vim 9.1 on Ubuntu 24.04 (WSL2), November 2026. Every Make, cat -A, grep, sed and Vim example ran as shown. The apt commands that need root (apt install) were not run; apt-cache and the command-not-found helper were queried instead. The winget and Chocolatey commands were read-only queries on Windows 11, and nothing was installed. wsl --install, the macOS commands (xcode-select, brew) and the EditorConfig snippet were not run, and the VS Code JSON was only checked for validity with jq.

Was this page helpful?
The Dark Debugger

Written by The Dark Debugger

Engineer documenting the things that took me too long to learn, so they take you less time. Every Makefile tutorial here is tested end to end before publishing.