Before writing your first Lean 4 proof you need three things on your machine: theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/leanprover-community/mathlib4/llms.txt
Use this file to discover all available pages before exploring further.
elan version manager (which installs and switches Lean toolchains), Lean 4 itself (including the Lake build system), and the VS Code Lean 4 extension for editor support. The whole process typically takes under ten minutes on a good connection. If you prefer not to install anything locally, a one-click cloud environment is available via GitHub Codespaces or Gitpod.
Prerequisites
- Operating system: Linux (x86_64 or ARM64), macOS (Intel or Apple Silicon), or Windows via WSL 2.
- Internet connection: elan downloads the Lean toolchain on first use (~200 MB).
- Disk space: ~2 GB for Lean, Lake, and Mathlib’s precompiled
.oleancache. - VS Code (recommended): code.visualstudio.com — required for the interactive proof-state display.
Option A: Local Installation (Recommended)
Install elan (the Lean version manager)
elan manages Lean toolchain versions the same way rustup manages Rust. Open a terminal and run:~/.elan/bin to your PATH.Install the current Lean 4 toolchain
elan installs Lean toolchains on demand. To pre-install the toolchain that Mathlib currently uses, run:This downloads the Lean 4 compiler and the Lake build system. You can confirm everything is in place:
The exact version above comes from Mathlib’s
lean-toolchain file (leanprover/lean4:v4.32.0-rc1). When you add Mathlib as a project dependency, elan automatically switches to the correct toolchain for that project.Install the VS Code Lean 4 extension
The Lean 4 extension provides the interactive infoview where you see proof states, goal displays, and error messages in real time.
- Open VS Code.
- Go to the Extensions panel (
Ctrl+Shift+X/Cmd+Shift+X). - Search for
lean4(publisher: leanprover). - Click Install.
.lean file.The lean-toolchain File
Every Lean project contains a lean-toolchain file in its root directory. This single-line file pins the exact Lean version used by that project. Mathlib’s current toolchain is:
cd into any directory containing a lean-toolchain file, elan transparently switches to that toolchain. This means different projects on the same machine can use different Lean versions without conflict. You never need to manually switch toolchains — elan handles it automatically.
Option B: Cloud Environment (No Installation Required)
If you want to experiment with Mathlib without installing anything locally, both of the following options spin up a fully configured environment in your browser:Cloud environments are great for quick experiments, tutorials, and workshops, but local installation is recommended for sustained development — the interactive proof state in VS Code is much more responsive with a local build.
| Platform | How to open |
|---|---|
| GitHub Codespaces | Click Open in GitHub Codespaces on the mathlib4 repository page, or visit codespaces.new/leanprover-community/mathlib4. |
| Gitpod | Click Open in Gitpod on the repository page, or prefix the GitHub URL: gitpod.io/#https://github.com/leanprover-community/mathlib4. |
.olean cache so you can start exploring immediately.
Troubleshooting
elan is installed but `lean` is not found after restarting the terminal
elan is installed but `lean` is not found after restarting the terminal
elan adds
~/.elan/bin to your shell profile (.bashrc, .zshrc, etc.) during installation. If the command is still not found, manually add the following line to your profile and restart:`lean --version` shows the wrong version inside a project directory
`lean --version` shows the wrong version inside a project directory
This is expected behavior. Inside a directory that contains a
lean-toolchain file, elan automatically reports the version pinned in that file. Run lean --version outside of any project directory to see your globally installed version.The VS Code extension shows 'Lean is not installed'
The VS Code extension shows 'Lean is not installed'
Make sure elan is on your
PATH (see above) and that you have restarted VS Code after installation. The extension invokes elan to locate Lean; if elan is not accessible, it cannot find Lean either.Installation fails on macOS with 'curl: (60) SSL certificate problem'
Installation fails on macOS with 'curl: (60) SSL certificate problem'
This usually means your system’s certificate store is outdated. Run
brew install ca-certificates (if you use Homebrew) or update macOS via System Settings → Software Update.