Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/leanprover/lean4/llms.txt

Use this file to discover all available pages before exploring further.

Building Lean 4 from source gives you full control over the compiler, lets you test local patches, and is a prerequisite for contributing to the project. These instructions are for people who want to change Lean itself. If you just want to use Lean, follow the official installation instructions instead, which use elan to manage versioned toolchains automatically.

Prerequisites

Every platform requires:
RequirementNotes
C++14-compatible compilerClang is recommended; GCC works too
CMake ≥ 3.10Used to configure and build
GMPGNU multiprecision library
LibUVAsync I/O, used by the language server
OpenSSLRequired for HTTPS downloads in Lake
CCache is strongly recommended. Lean’s build system detects it automatically and uses it to cache compiled C files, dramatically reducing rebuild times after stage0 is updated.

Platform-Specific Setup

Install all dependencies with a single command:
sudo apt-get install \
  git libgmp-dev libuv1-dev libssl-dev \
  cmake ccache clang pkgconf
Then proceed to Generic Build Instructions.

Generic Build Instructions

1

Clone the repository

git clone https://github.com/leanprover/lean4
cd lean4
2

Configure with a CMake preset

Choose a preset based on your goal:
PresetDescriptionOutput dir
releaseOptimized build, stripped binariesbuild/release
dev-releaseOptimized + debug symbols (-g3), warnings as infobuild/release
debugCMAKE_BUILD_TYPE=Debug, large stack, full symbolsbuild/debug
sandebugSanitize + debug (AddressSanitizer, UBSan)build/sandebug
For everyday development, dev-release is recommended:
cmake --preset dev-release
For a clean release (CI / distribution):
cmake --preset release
3

Build

make -C build/release -j$(nproc || sysctl -n hw.logicalcpu)
Replace the parallelism expression with an explicit number if you prefer, e.g. -j8. The build produces stage0/ and stage1/ subdirectories inside build/release/.
4

Verify the build

./build/release/stage1/bin/lean --version
If a make invocation fails and you want to see the exact compiler commands being run, add VERBOSE=1:
make -C build/release VERBOSE=1

CMake Configuration Options

Pass any of these alongside cmake --preset <name>:
cmake --preset release \
  -DCMAKE_BUILD_TYPE=RELEASE \
  -DCMAKE_C_COMPILER=clang \
  -DCMAKE_CXX_COMPILER=clang++
OptionValid valuesDefault
CMAKE_BUILD_TYPERELEASE, DEBUG, RELWITHDEBINFO, MINSIZERELRELEASE
CMAKE_C_COMPILERpath to C compilersystem default
CMAKE_CXX_COMPILERpath to C++ compilersystem default
STRIP_BINARIESON / OFFOFF in dev presets
WFAILON / OFF — treat warnings as errorsON in release
Official Lean releases are built with Clang. CI configuration is in .github/workflows/ci.yml.

Build Output Structure

After a successful build, the build/release/ directory contains:
stage0/
  bin/lean          # bootstrap compiler built from stage0/src/ (C sources)

stage1/
  bin/
    lean            # the Lean compiler and language server
    leanc           # wrapper around the C compiler with Lean search paths
    leanmake        # wrapper around make supplying lean.mk
  include/
    lean/
      lean.h          # runtime header for FFI consumers (#include <lean/lean.h>)
      config.h        # compile-time configuration variables
      version.h       # version information
  lib/
    lean/**/*.olean         # compiled Lean library (stdlib + compiler)
    temp/**/*.{c,o}         # C code extracted from Lean sources
    libInit.a libLean.a     # static libraries
    libleancpp.a            # C++ runtime and builtins
    libleanshared.so        # dynamic library bundling the above

stage2/  # sanity-check stage, should equal stage1
stage3/  # further sanity check
Running make alone builds through stage1, which is sufficient for testing changes on external files. Stage 2 and 3 are needed to verify that compiler changes are self-consistent. See the Development Workflow page for details on the bootstrapping pipeline.

CCache Integration

Lean’s build system detects and uses CCache automatically when it is on your PATH. CCache caches compiled C files and is especially useful after a stage0 update, where all the extracted C files must be recompiled but are identical to those from a recent build. Verify that CCache is active:
ccache --show-stats

Building Additional Stages

# Build stage1 (default)
make -C build/release

# Build stage2 (needed when .olean format changes)
make -C build/release stage2

# Build stage3 (sanity check)
make -C build/release stage3

Build docs developers (and LLMs) love