$linuxjunkies
>

ninja(1)

A small build system with a focus on speed, designed to drive compilation of large projects.

UbuntuDebianFedoraArch

Synopsis

ninja [OPTION]... [TARGET]...

Description

Ninja is a build system that emphasizes speed and simplicity. It reads a build manifest (usually generated by higher-level build systems like CMake, Meson, or Bazel) and executes the build graph as efficiently as possible, with built-in support for parallel execution and dependency tracking.

Unlike Make, Ninja uses a simpler syntax optimized for machine generation rather than hand-writing. It automatically parallelizes independent build tasks and reuses build results across incremental builds for speed.

Common options

FlagWhat it does
-C DIRChange to directory DIR before reading the build.ninja file
-f FILEUse FILE as the build manifest (default: build.ninja)
-j NUMRun NUM jobs in parallel (default: number of CPU cores)
-vShow all command lines while building
-d MODEEnable debugging output; MODE can be stats, explain, or keepdepfile
-t TOOLRun tool TOOL; useful tools include clean, deps, query, targets, rules, and graph
-k NUMKeep building until NUM jobs fail (default: 1; 0 builds everything)
-nDry run; print commands that would be executed without running them

Examples

Build all targets defined in build.ninja in the current directory

ninja

Build the target 'mytarget' using 4 parallel jobs

ninja -j 4 mytarget

Build using custom.ninja manifest in the build/ subdirectory

ninja -C build -f custom.ninja

Remove all built files without rebuilding

ninja -t clean

Generate a dependency graph of mytarget and visualize it as an image

ninja -t graph mytarget | dot -Tpng > deps.png

Show all commands that would execute for target1 and target2 without running them

ninja -v -n target1 target2

Build as much as possible, stopping only after 10 jobs fail

ninja -k 10

List all available targets and filter for those with 'test' in the name

ninja -t targets | grep test

Related commands