How to bump Mathlib in a Lean 4 project
Move your pin to a newer Mathlib tag, rebuild, and fix what the compiler reports. This is the procedure, with output taken from public projects bumped to Mathlib v4.35.0.
Scan your project first Look up a name
Last updated 2026-11-13. Mathlib target in the examples: v4.35.0 (Lean leanprover/lean4:v4.35.0).
1. Find your pin and choose the next tag
Your pin is the rev of mathlib in lake-manifest.json, and the require mathlib line in your lakefile.toml or lakefile.lean. Mathlib tags a release v4.X.0 for each Lean release, so a pin on a tag tells you how far behind you are.
If you are more than a few releases behind, move one tag at a time rather than straight to the newest. A deprecated name keeps working as an alias for a median of 6 releases and is then deleted, after which the compiler no longer tells you what replaced it (the numbers). Each single step keeps the warnings useful.
2. Set the toolchain and the dependency
curl -L https://raw.githubusercontent.com/leanprover-community/mathlib4/v4.35.0/lean-toolchain -o lean-toolchain
# in lakefile.toml: rev = "v4.35.0" (or in lakefile.lean: require mathlib from git "https://github.com/leanprover-community/mathlib4" @ "v4.35.0")
lake update mathlib
lake exe cache get
lake exe cache get downloads Mathlib's compiled files so you do not rebuild them. A bump of PrimeCert from v4.31.0 to v4.35.0 logged info: leanprover-community/mathlib: fetching revision 'v4.35.0' for the update and Already decompressed 9031 file(s) from the cache.
3. Build and sort what you get
lake build 2>&1 | tee build.log
The output has two kinds of line that need different handling.
Deprecation warnings: the compiler names the replacement
From Lean Machine Learning at v4.35.0:
warning: LeanMachineLearning/ForMathlib/MeasureTheory/Order/MeasurableArg.lean:77:13:
`Set.mem_setOf_eq` has been deprecated: Use `Set.mem_ofPred_eq` instead
Replace the old name with the one in the message and rebuild. Across the 7 pilot projects that broke at the bump, 52 of the 67 deprecation warnings carried a replacement of this kind (the other 15 name declarations from core Lean, outside Mathlib's own history).
Errors: the build stops here, and a rename does not fix them
From PrimeCert at v4.35.0:
error: PrimeCert/PowMod.lean:101:49: Ambiguous term
powMod
Possible interpretations:
_root_.powMod a b n : ℕ
a.powMod b n : ℕ
Here the project's own powMod (defined at the root) now clashes with a Nat.powMod that Lean core added (Init/Data/Nat/PowMod.lean in v4.35.0), so the fix is to rename or remove the local declaration, or write _root_.powMod explicitly. In the same projects, 135 of the 145 raw errors named no declaration at all: changed statements, new upstream names that clash with local ones, simp lemmas that no longer fire, lemmas that gained a hypothesis. An alias map resolved 0 of those 145. That is why the order below matters.
The one that costs time: unknown identifier
It means the name is gone. Look it up in the rename lookup (19,673 deprecated Mathlib names, v4.0.0 to v4.36.0). If the answer is a new name, check whether it takes the same arguments: a replacement with a different signature compiles only after you adapt the call. When the lookup shows no record, search the Mathlib git history for the declaration's last commit, as the deprecation was removed without an alias.
4. Fix in this order
- Renames first. The deprecation warnings and the names in the lookup: mechanical, and each one removes noise from the error list. A scan lists them all by file and line before you build.
- Then the first error in the first file. Lean reports errors per file in dependency order, so fixing a module exposes its dependents. Raw counts are a lower bound: PrimeCert went from 8 errors to 13 as its first module was repaired.
- Rebuild after each file (
lake build MyProject.Module), not after each line. - Review every change that touches a statement. A fix that adds a hypothesis to a theorem makes the build pass and changes what it proves; the benchmark flags these where they occurred.
5. Commit one release per step
When lake build exits 0, commit with the tag in the message, then start the next tag from there. A bisectable history per release lets you find which bump changed a proof when something regresses later.
Skip the first hour
Paste your repository: the scan reads your pin, finds deprecated Mathlib names your project uses with the new name beside each where Mathlib names one, and downloads those renames as one diff. No account and no build.
Method: the command output above is from bench/runs/ in the Leanbump benchmark (8 public projects, one bump each to v4.35.0, lake build exit status as the test); the counts are from bench/alias_audit.json.