0Pricing
Zig Academy · Lesson

Compile and Run in One Step

Use zig run to go from source to output.

Compile and Run in One Step is a free Zig Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Zig Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

From Source to Running

Normally you compile code into a binary, then run it. Zig folds both into a single friendly command: zig run. ⚡

The zig run Command

Point zig run at a source file and it compiles your program and immediately executes the result, all in one go.

zig run hello.zig

No Build File Required

For a single file you need no build script and no project setup. That makes zig run perfect for quick experiments and learning.

What Happens Under the Hood

Behind the scenes Zig still compiles to native machine code first. You simply never have to name or launch the binary yourself.

Temporary Binary

The executable from zig run is placed in a cache and run for you. It is not dropped into your folder as a permanent file.

Passing Arguments to Your Program

Put two dashes after the file name, then your program's own arguments follow. Zig hands everything after -- to your code.

zig run main.zig -- input.txt --verbose

Choosing an Optimization Mode

Add an optimize flag to control speed and safety. The default is the safe Debug mode, which keeps checks turned on.

zig run main.zig -O ReleaseFast

Caching Speeds Reruns

Zig caches compiled artifacts, so running the same unchanged file again skips most work and starts almost instantly.

When You Want a Real File

To keep a binary you can ship, use zig build-exe instead. It writes an executable to disk rather than running it for you.

zig build-exe hello.zig

zig run for the Inner Loop

During development you live in a tight edit-run loop. zig run keeps that loop fast: change the file, run it, see output, repeat.

Errors Stop the Run

If your code will not compile, zig run prints the errors and never runs anything. A clean compile is required before execution.

Quick Check

You have one file, app.zig, and want to compile and execute it in a single command. Which do you use?

Recap

Use zig run to compile and execute a file in one step, great for fast iteration. Reach for zig build-exe when you need a binary to keep. 🎯

Frequently asked questions

Is the “Compile and Run in One Step” lesson free?

Yes — the full text of “Compile and Run in One Step” is free to read here on the web, and the Zig Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Zig Academy course, upgrade to CoddyKit PRO.

What will I learn in “Compile and Run in One Step”?

Use zig run to go from source to output. You practise Zig Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Zig Academy?

No prior experience is required. Zig Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Compile and Run in One Step” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Zig Academy lesson?

Yes. Every Zig Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Install Zig on Any Platform
  2. Your First main Function
  3. Printing with std.debug.print
  4. Compile and Run in One Step
← Back to Zig Academy