This guide takes you from zero to a working Lean 4 project in under ten minutes. You will installDocumentation 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.
elan (the Lean version manager), create a new package with lake, run the generated Hello World, write a small function, and prove a theorem about it — all without needing to configure anything by hand.
Prerequisites
- A Unix-like system (Linux, macOS) or Windows with PowerShell
- An internet connection for downloading the toolchain
- VS Code (recommended; optional)
elan is the official Lean toolchain manager, similar to rustup for Rust. It downloads and manages Lean versions automatically. Linux / macOS
leanprover/lean4:stable). After installation, restart your shell or run: Windows (PowerShell)
macOS Homebrew
lean --version
# Lean (version 4.x.x, ...)
lake --version
# Lake version x.x.x (Lean version 4.x.x)
hello/
├── Hello/
│ └── Basic.lean -- Example library module
├── Hello.lean -- Library root (imports Hello.Basic)
├── Main.lean -- Executable entry point
├── lakefile.toml -- Build configuration (TOML format)
└── lean-toolchain -- Pinned Lean version
The
lean-toolchain file pins the exact Lean version used by this project. When you open the project in VS Code or run any lake command, elan reads this file and automatically downloads the correct toolchain if it is not already installed.-- This module serves as the root of the `Hello` library.
-- Import modules here that should be built as part of the library.
import «Hello».Basic
Install the Lean 4 extension from the VS Code marketplace (identifier:
leanprover.lean4), then open the project folder:The extension automatically detects the
lean-toolchain file. Open any .lean file and you will see:The first time you open a Lean file, the extension downloads the language server. This can take a minute. Watch the spinning indicator in the status bar.
/-- Double a natural number. -/
def double (n : Nat) : Nat := n + n
/-- Triple a natural number. -/
def triple (n : Nat) : Nat := n + n + n
-- Quick evaluation in the editor (hover to see the result)
#eval double 7 -- 14
#eval triple 5 -- 15
/-- Doubling is the same as multiplying by two. -/
theorem double_eq_two_mul (n : Nat) : double n = 2 * n := by
simp [double, Nat.two_mul]
/-- Tripling a number gives a value greater than doubling it (for n > 0). -/
theorem triple_gt_double (n : Nat) (h : 0 < n) : double n < triple n := by
simp [double, triple]
omega
Place your cursor on the
by keyword to see the tactic goal state in the Lean Infoview panel on the right.The lean-toolchain File
The lean-toolchain file created by lake new contains a single line like:
elan to use that exact release. To update to a newer release, edit this file or run:
Next Steps
Installation
Full installation details including editor setup for Emacs and Neovim.
Syntax Overview
Namespaces, imports, sections, and the
#check / #eval commands.Functions & Definitions
def, theorem, recursion, implicit arguments, and attributes.Inductive Types
Algebraic data types, pattern matching, and the
deriving clause.