How can I install and use "make" in Windows?
Categories:
Mastering Make: A Guide to Installing and Using Make on Windows

Unlock the power of Makefiles on your Windows machine. This guide covers installation, configuration, and basic usage of GNU Make, streamlining your build processes.
While make
is a ubiquitous build automation tool in Unix-like environments, Windows users often find themselves without a native equivalent. However, with a few straightforward steps, you can install and leverage GNU Make on your Windows system, bringing its powerful automation capabilities to your development workflow. This article will guide you through the process, from installation to running your first Makefile.
Understanding Make and Makefiles
Before diving into installation, it's helpful to understand what make
does. Make
is a utility that automatically builds executable programs and libraries from source code by reading files called Makefiles which specify how to derive the target program. It intelligently determines which parts of a program need to be recompiled and issues the commands to recompile them, saving significant time in large projects. Makefiles define rules, where each rule specifies a target, its dependencies, and the commands needed to create or update the target.
flowchart TD A["Start Build Process"] --> B{"Target File Exists?"} B -->|No| C["Check Dependencies"] C --> D{"Dependencies Up-to-Date?"} D -->|No| E["Execute Commands to Build Target"] E --> F["Target Built/Updated"] D -->|Yes| F B -->|Yes| G{"Target Newer than Dependencies?"} G -->|No| E G -->|Yes| H["Target is Up-to-Date"] F --> I["End Build Process"] H --> I
Simplified Workflow of the 'make' Utility
Installation Methods for GNU Make on Windows
There are several ways to get GNU Make running on Windows. The most common and recommended methods involve using a package manager or a Unix-like environment. We'll focus on two popular approaches: using MSYS2 and Chocolatey.
Method 1: Installing Make with MSYS2
MSYS2 provides a Unix-like environment and a software repository for Windows, making it an excellent choice for installing GNU tools like make
. It includes a package manager called pacman
.
1. Download MSYS2
Visit the official MSYS2 website (msys2.org) and download the installer. Choose the appropriate version for your system (64-bit is most common).
2. Install MSYS2
Run the downloaded installer. Follow the on-screen prompts. It's generally recommended to install it to the default path (e.g., C:\msys64
).
3. Update MSYS2 Packages
After installation, open the MSYS2 MSYS terminal (from the Start Menu). Run the following commands to update the package database and core packages:
pacman -Syu
pacman -Su
4. Install GNU Make
Once MSYS2 is updated, you can install make
using pacman
:
pacman -S make
5. Verify Installation
Close and reopen the MSYS2 MSYS terminal. Type make -v
to confirm that make
is installed and displays its version information.
Method 2: Installing Make with Chocolatey
Chocolatey is a popular package manager for Windows, similar to apt
or yum
on Linux. It simplifies the installation of many software packages, including GNU Make.
1. Install Chocolatey (if not already installed)
Open PowerShell as an administrator. Run the following command to install Chocolatey:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
After installation, close and reopen PowerShell as administrator.
2. Install GNU Make
In the administrative PowerShell window, run the command to install make
:
choco install make
Chocolatey will download and install GNU Make, often adding it to your system's PATH automatically.
3. Verify Installation
Open a new Command Prompt or PowerShell window (not necessarily administrative). Type make -v
to check the installation. If it's not found, you might need to restart your computer or manually add the make
executable's directory to your system's PATH environment variable.
Creating and Running Your First Makefile
Now that make
is installed, let's create a simple Makefile to see it in action. This example will compile a basic C program.
#include <stdio.h>
int main() {
printf("Hello from Make on Windows!\n");
return 0;
}
CC = gcc
CFLAGS = -Wall -g
all: hello
hello: main.o
$(CC) $(CFLAGS) -o hello main.o
main.o: main.c
$(CC) $(CFLAGS) -c main.c
clean:
rm -f *.o hello
1. Save the files
Save the C code as main.c
and the Makefile content as Makefile
(no extension) in the same directory.
2. Open a terminal
Navigate to that directory using either the MSYS2 terminal (if you used Method 1) or Command Prompt/PowerShell (if you used Method 2 and make
is in your PATH).
3. Run make
Execute the command make
. This will trigger the all
target, which depends on hello
, which in turn depends on main.o
and main.c
. make
will compile main.c
into main.o
and then link it into hello.exe
(or just hello
in MSYS2).
4. Run the executable
After make
completes, run your program: ./hello
(in MSYS2) or hello.exe
(in Command Prompt/PowerShell).
5. Clean up
To remove the generated files, run make clean
.
pacman -S mingw-w64-x86_64-gcc
. If using Chocolatey, choco install mingw
is an option.