These are instructions to set up a working development environment for those who wish to make changes to Lean itself. It is part of the Development Guide.

We strongly suggest that new users instead follow the Installation Instructions to get started using Lean, since this sets up an environment that can automatically manage multiple Lean toolchain versions, which is necessary when working within the Lean ecosystem.

Requirements

Platform-Specific Setup

Generic Build Instructions

Setting up a basic parallelized release build:

git clone https://github.com/leanprover/lean4
cd lean4
cmake --preset release
make -C build/release -j$(nproc || sysctl -n hw.logicalcpu)

For development, cmake --preset dev-release (reusing the same build/release output directory) is recommended instead.

You can replace $(nproc || sysctl -n hw.logicalcpu) with the desired parallelism amount.

The above commands will compile the Lean library and binaries into the stage1 subfolder; see below for details.

Linux and macOS release toolchains also include Lean Beam. To include it in a local build on these platforms, run make -C build/release lean-beam after the ordinary build. This target fetches a pinned Beam revision and builds its CLI, daemon, MCP server, and plugin with the local toolchain. The executables reuse the toolchain's shared Lean and Lake libraries. The bundled lean-beam and lean-beam-mcp use only that toolchain and do not build additional runtimes when invoked in a project. Windows distribution support is deferred pending further validation.

You should not usually run cmake --install after a successful build. See Dev setup using elan on how to properly set up your editor to use the correct stage depending on the source directory.

Useful CMake Configuration Settings

Pass these along with the cmake --preset release command. There are also two alternative presets that combine some of these options you can use instead of release: debug and sandebug (sanitize + debug).

  • -DCMAKE_BUILD_TYPE=
    Select the build type. Valid values are RELEASE (default), DEBUG, RELWITHDEBINFO, and MINSIZEREL.

  • -DCMAKE_C_COMPILER=
    -DCMAKE_CXX_COMPILER=
    Select the C/C++ compilers to use. Official Lean releases currently use Clang; see also .github/workflows/ci.yml for the CI config.

  • -DUSE_GMP=
    Use GMP for arbitrary-precision integers (default ON). Lean requires GMP 6.3.0 or newer, because earlier versions contain bugs that can make Lean produce unsound results. Set -DUSE_GMP=OFF to use Lean's built-in bignum implementation instead, which needs no external GMP (safest; some performance cost).

  • -DFORCE_GMP=
    Build against the GMP found on the system even if it is older than 6.3.0 (default OFF). Not recommended: Lean may produce unsound results in corner cases. Independent kernels that do not depend on GMP will catch the unsoundness.

Lean will automatically use CCache if available to avoid redundant builds, especially after stage 0 has been updated.

Troubleshooting

  • Call make with an additional VERBOSE=1 argument to print executed commands.