Mojo Get Started
Let’s get Mojo running on your computer and write your first program. It takes about ten minutes. You’ll install Mojo, run a tiny program, turn it into a real app, and learn how to read Mojo’s error messages.
Every Mojo example and output on this page was checked with Mojo 1.2 on Linux.
Step 1: Check your computer
Section titled “Step 1: Check your computer”Mojo runs on three kinds of systems. The official system requirements list the details, but here’s the short version:
| System | What you need |
|---|---|
| macOS | A Mac with Apple silicon (M1 or newer) and macOS 15 Sequoia or later |
| Linux | A recent distribution, for example Ubuntu 22.04 or later |
| Windows | Windows itself isn’t supported, but Mojo works inside WSL (Windows Subsystem for Linux) |
Step 2: Install uv
Section titled “Step 2: Install uv”Mojo is installed like a Python package. The easiest tool for that is uv, a small, fast package manager for Python projects. If you don’t have it yet, open a terminal and run:
curl -LsSf https://astral.sh/uv/install.sh | shClose the terminal and open a new one, so it picks up the new uv command.
Step 3: Create a project and add Mojo
Section titled “Step 3: Create a project and add Mojo”Make a folder for your project and add Mojo to it:
uv init hello-worldcd hello-worlduv add mojouv init creates the folder with a few starter files (pyproject.toml, main.py, README.md). You can ignore those; they’re for Python. uv add mojo downloads Mojo into a hidden .venv folder inside your project. The first time takes a minute or two.
Step 4: Check it worked
Section titled “Step 4: Check it worked”Ask Mojo for its version:
uv run mojo --versionOutput:
Mojo 1.2.0 (2016d0cd)If you see a version number, Mojo is installed. The number in brackets is the exact build, so yours may differ slightly.
uv run means “run this command using the tools in this project”. Typing it every time gets old, so turn on the project’s environment once per terminal window:
source .venv/bin/activateNow you can type plain mojo. The rest of this tutorial assumes you’ve done this.
Step 5: Write your first program
Section titled “Step 5: Write your first program”Create a file called hello.mojo in your hello-world folder (any text editor works) and put this in it:
def main(): print("Hello, Mojo!")Run it:
mojo hello.mojoOutput:
Hello, Mojo!That’s your first Mojo program.
Understanding the code
Section titled “Understanding the code”There are only two lines, but each one matters:
def main():defines a function calledmain. Every Mojo program starts running atmain. If you know Python,deflooks familiar: Mojo uses it for functions too.print("Hello, Mojo!")prints the text between the quotes, followed by a new line.- The indentation (the four spaces before
print) is how Mojo knows thatprintbelongs insidemain. Just like Python, there are no curly braces.
You can put more lines inside main, and they run from top to bottom:
def main(): print("Hello, Mojo!") print("I am learning Mojo.") print(2 + 3)Output:
Hello, Mojo!I am learning Mojo.5print(2 + 3) works out the sum first, then prints the result.
Running vs building
Section titled “Running vs building”So far you’ve used mojo hello.mojo, which compiles and runs the file in one go. That’s what you’ll use most while learning.
When you want a finished program you can run again without compiling it each time, build it:
mojo build hello.mojo./helloOutput:
Hello, Mojo!mojo build turns your code into an executable file called hello (named after your .mojo file). You run it with ./hello, and it starts instantly because the compiling already happened. To pick a different name, add -o:
mojo build hello.mojo -o greeter./greeter| Command | What it does | Use it when |
|---|---|---|
mojo hello.mojo |
Compiles and runs right away | You’re writing and testing code |
mojo build hello.mojo |
Makes an executable file | You want a finished program |
When something goes wrong
Section titled “When something goes wrong”Everyone makes typos. Here’s what happens if you misspell print:
def main(): prnt("Hello, Mojo!")/home/you/hello-world/hello.mojo:2:5: error: use of unknown declaration 'prnt' prnt("Hello, Mojo!") ^~~~mojo: error: failed to parse the provided Mojo source moduleIt looks scary at first, but it’s telling you exactly where to look:
hello.mojo:2:5means line 2, column 5 ofhello.mojo.use of unknown declaration 'prnt'means Mojo doesn’t know anything calledprnt.- The
^~~~marks the exact spot.
Fix the spelling and run it again. The last line (failed to parse...) just says the program couldn’t be built; the useful part is always the first error: line.
Prefer pixi?
Section titled “Prefer pixi?”The official docs also show pixi, another package manager that some Mojo users like. It works just as well. If you’d rather use it, these are the commands from the official install page:
curl -fsSL https://pixi.sh/install.sh | shpixi init hello-world -c https://conda.modular.com/max/ -c conda-forgecd hello-worldpixi add mojopixi run mojo --versionPick one tool and stick with it. This tutorial uses uv.
Step 6: Set up your editor (recommended)
Section titled “Step 6: Set up your editor (recommended)”You can write Mojo in any text editor, but the official extension for VS Code makes life much easier: colors for your code, suggestions as you type, and errors shown right where they happen.
Install the Mojo extension from the VS Code Marketplace, then open your hello-world folder in VS Code. If you use an editor based on VS Code that reads from the Open VSX Registry, the extension is there too.
Practice
Section titled “Practice”1. Three lines
Section titled “1. Three lines”Change hello.mojo so it prints three lines: your name, the sentence I'm learning Mojo., and the result of 7 * 6.
Hint: each print gets its own line inside main, indented with four spaces.
Show solution
def main(): print("My name is Sam.") print("I'm learning Mojo.") print(7 * 6)Output:
My name is Sam.I'm learning Mojo.42Each print runs in order, top to bottom. print(7 * 6) works out the multiplication first and prints 42.
2. Build an app called greet
Section titled “2. Build an app called greet”Write a file greet.mojo that prints Hi from a real program!, then build it into an executable called greet and run it.
Hint: use mojo build with the -o option to choose the name.
Show solution
def main(): print("Hi from a real program!")mojo build greet.mojo -o greet./greetOutput:
Hi from a real program!mojo build compiles the file into an executable. -o greet names it greet, and ./greet runs it from the current folder.
- Mojo runs on macOS (Apple silicon), Linux, and Windows through WSL.
- Install it into a project with uv:
uv init, thenuv add mojo. - Run
source .venv/bin/activateonce per terminal so you can typemojo. - Every program starts at
def main():, and indentation shows what’s inside it. mojo file.mojocompiles and runs;mojo build file.mojomakes an executable (it still needs Mojo’s libraries).- In an error, look for the file, line and column and the first
error:line.
Next up: Mojo tools & setup, a tour of the mojo command and your editor.
Quick check
Section titled “Quick check”Quick check
Read more
Section titled “Read more”- Install Mojo: the official install page, with the uv and pixi commands.
- System requirements: exactly which macOS, Linux and WSL setups are supported.
- Mojo quickstart: the official 15-minute tour, a good next step after this page.
- uv documentation: more about the tool that installs Mojo into your project.
- Mojo extension for VS Code: syntax colors, completion and debugging in your editor.