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.

Lean 4 is distributed through elan, the official Lean toolchain version manager. Elan handles downloading, caching, and switching between Lean releases, so you never need to manage binaries by hand. This page covers installing elan on every supported platform, setting up your editor, and managing toolchains day-to-day.

Install elan

Run the elan installer script:
curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh
The installer will:
  1. Download the elan binary to ~/.elan/bin/
  2. Add ~/.elan/bin to your PATH in ~/.profile (or ~/.bash_profile, ~/.zshenv, etc.)
  3. Optionally download a default Lean toolchain
Restart your shell or run:
source ~/.elan/env

Verify the Installation

lean --version
# Lean (version 4.x.x, commit xxxxxxxx, Release)

lake --version
# Lake version x.x.x (Lean version 4.x.x)
If either command is not found, ensure ~/.elan/bin is in your PATH.

Editor Support

Install the official extension from the VS Code marketplace:
  • Extension ID: leanprover.lean4
  • Name: Lean 4
# Install via the command line
code --install-extension leanprover.lean4
Or open VS Code, press Ctrl+P / Cmd+P, and type:
ext install leanprover.lean4
Key features:
  • Real-time type checking and error messages
  • Lean Infoview panel showing tactic goal states
  • Hover for types and docstrings
  • Go-to-definition (F12) across packages
  • Breadcrumbs, outline, and find-all-references
Open the Lean Infoview panel with Ctrl+Shift+Enter (or via the command palette: “Lean 4: Open Infoview”). Place your cursor inside any by block to see the live proof state.

Emacs

Install lean4-mode from MELPA:
;; In your init.el / .emacs
(use-package lean4-mode
  :ensure t
  :commands lean4-mode)
Or with straight.el:
(straight-use-package 'lean4-mode)
lean4-mode uses elan to locate the correct lean binary automatically. Make sure ~/.elan/bin is in Emacs’s exec-path, or set:
(setq lean4-rootdir "~/.elan")

Neovim

Use your plugin manager to install lean.nvim:
{
  "Julian/lean.nvim",
  dependencies = {
    "neovim/nvim-lspconfig",
    "nvim-lua/plenary.nvim",
  },
  opts = {
    lsp = { on_attach = on_attach },
    mappings = true,
  },
}
lean.nvim communicates with the Lean language server via LSP. The infoview is available with :LeanInfoviewToggle.

A Minimal Lean 4 File

Once installed, verify everything works end-to-end by running lean directly on a file:
-- Save as hello.lean and run: lean --run hello.lean
def main : IO Unit :=
  IO.println "Lean 4 is installed and working!"
lean --run hello.lean
# Lean 4 is installed and working!

Elan Toolchain Management

Install a Specific Toolchain

# Install the stable release
elan toolchain install leanprover/lean4:stable

# Install a specific version
elan toolchain install leanprover/lean4:v4.14.0

# Install the nightly channel
elan toolchain install leanprover/lean4:nightly

Set the Global Default

elan default leanprover/lean4:stable
This sets the toolchain used when you are outside a project directory (i.e., no lean-toolchain file is found in the current directory tree).

List Installed Toolchains

elan toolchain list

Remove a Toolchain

elan toolchain uninstall leanprover/lean4:v4.12.0

The lean-toolchain File

When lake new creates a project, it generates a lean-toolchain file in the project root:
leanprover/lean4:v4.14.0
Elan reads this file and automatically uses the pinned toolchain for all lean, lake, and related commands run inside that directory. This ensures every contributor uses the same Lean version.
# Override the toolchain for a single command
lean +leanprover/lean4:v4.13.0 --version

# Show which lean binary elan resolves to
elan which lean
You can also use a GitHub fork toolchain in lean-toolchain by writing <github-user>/lean4:<tag>. This is useful for testing against pre-release builds.

Building Lean from Source

If you need to build Lean itself (for contributing or debugging), see the official build instructions in the repository. Building from source requires CMake, a C++ compiler, and an existing Lean stage-0 binary.
Building from source is not required for using Lean 4. Unless you are contributing to the compiler itself, install via elan.

Build docs developers (and LLMs) love