Lean 4 installed
After finishing this section, you will have a Test.lean file on your computer in which Lean has computed the result of 1 + 1.
The officially recommended installation method is VS Code plus the Lean 4 extension; the extension then walks you through the rest. We'll follow this path first.
Before you start
- A Windows, macOS, or Linux computer with internet access
- Just want to try it first without installing: go straight to "Without installing" at the end of this page
Step 1: Install VS Code
Download and install VS Code from code.visualstudio.com. Skip this if it's already installed.
You should see: the VS Code main interface opens.
- VS Code opens
Step 2: Install the Lean 4 extension
In the VS Code extension marketplace, search for and install the official Lean 4 extension, identified by leanprover.lean4.
If you prefer the command line, this single command does the same thing:
code --install-extension leanprover.lean4Official note: the leanprover.lean4 in the command must be written in full, otherwise the official extension won't be installed.
- Lean 4 appears in the extension list
Step 3: Follow the extension to complete setup
The extension comes with a setup guide. If it doesn't open automatically:
- Create a new empty file:
File > New Text File, or pressCtrl+N(on macOS,Cmd+N). - Click the
∀symbol in the top right corner of the window. - Select
Documentation > Docs: Show Setup Guide….
Follow the guide to the end. It will install elan for you, which is Lean's version manager.
- The setup guide is complete
Step 4: Have Lean compute 1 + 1
- Create a new file and save it as
Test.lean. On the first save, a small popup appears in the bottom right corner of VS Code while Lean's toolchain installs in the background; wait for it to finish. - Type this into the file:
#eval 1 + 1You should see: no warnings or errors. Hover over the underlined #eval and the tooltip shows the result of the computation:
2- The
#eval 1 + 1inTest.leandisplays 2
Alternative installation: command line only
Instead of the VS Code guide, you can also install elan yourself. Lean requires git and curl.
Linux and macOS:
curl https://elan.lean-lang.org/elan-init.sh -sSf | shWhen prompted, choose 1 and accept the defaults. Then make the current terminal recognize the newly installed commands:
source $HOME/.elan/envWindows(PowerShell):
curl -O --location https://elan.lean-lang.org/elan-init.ps1
powershell -ExecutionPolicy Bypass -f elan-init.ps1
del elan-init.ps1After installation, verify:
lean --version$lean --version
Lean (version 4.35.0, x86_64-unknown-linux-gnu, commit eb6cafb7290e8bd5f2937522d8d804f58f02bafc, Release)
You should see: a line starting with Lean (version followed by a version number. The code in this course was checked with 4.35.0; a newer version is fine too.
The official recommendation is still to prefer the VS Code method above; after installing via the command line, you'll still need an editor that can display goal states when writing proofs.
Without installing
There is an official online version: live.lean-lang.org. Lean runs on their servers, and you write code in the browser. It's positioned for beginners to try before installing, and for running small snippets; it's not suitable for large projects.
The code in the first few sections of this course is very short, so you can follow along there first and install once you reach the chapter on induction.
Didn't work?
The terminal says lake or lean cannot be found. elan's path hasn't taken effect yet. Run source $HOME/.elan/env, or close and reopen the terminal. If your system suggests installing with sudo apt install elan, don't follow it; just add the path as described above.
Nothing happens for a long time after saving Test.lean. The first save downloads the full toolchain in the background, with a progress popup in the bottom right corner. Wait for it to finish before checking the result.
Checkpoint
- The Lean 4 extension is installed in VS Code
#eval 1 + 1inTest.leandisplays 2- I know the URL of the online version and can use it first if the installation fails
FAQ
How do I download Lean 4?
The officially recommended download method is to first install VS Code from code.visualstudio.com, then install the official Lean 4 extension identified by leanprover.lean4 in the extension marketplace. After installation, follow the extension's built-in setup guide, which will install elan for you. If you don't want to install VS Code, you can also install elan directly with a command-line script; see "Alternative installation: command line only" above.
What is the official download site for Lean 4?
VS Code is downloaded from code.visualstudio.com; the script address used to install elan from the command line is in "Alternative installation: command line only" above.
Can I try Lean 4 first without downloading and installing it?
Yes. There is an official online version, live.lean-lang.org, where Lean runs on their servers and you write code in the browser. The code in the first few sections of this course is very short, so you can follow along there first.
After downloading and installing, the terminal says lake or lean cannot be found. What should I do?
This means elan's path hasn't taken effect yet. Run source $HOME/.elan/env, or close and reopen the terminal. If your system suggests installing with sudo apt install elan, don't follow it.
Next section
You have the tools now. In First Proof, you will write a theorem and have Lean confirm it.