Zig Get Started
Let’s get Zig onto your computer and write your first program. It takes about ten minutes. You’ll download Zig, check that it works, run a tiny program, turn it into a real executable and learn how to read Zig’s error messages, which you’ll see a lot of at first (everyone does).
Every example and output on this page was checked with Zig 0.17.1 on Linux.
Pick the right version
Section titled “Pick the right version”Zig hasn’t reached 1.0 yet, so each release still changes the language and the standard library. Code written for one version often doesn’t compile on the next one. That’s normal for Zig right now, and it’s the main thing to know before you install.
This tutorial is written for Zig 0.17.1, the latest stable release (November 2026). The download page shows it at the top, under “Latest Stable Version”. Right below it is the “Bleeding Edge” development version (master): skip that one, it changes every day and the examples here aren’t checked against it. Older releases are listed further down.
Step 1: Download Zig
Section titled “Step 1: Download Zig”The official Getting Started page recommends the direct download as the simplest way. Open the download page, find the 0.17.1 section and pick the file for your computer:
| Your computer | File to download |
|---|---|
| Windows (most PCs) | zig-x86_64-windows-0.17.1.zip |
| Windows on ARM | zig-aarch64-windows-0.17.1.zip |
| Mac with Apple silicon (M1 or newer) | zig-aarch64-macos-0.17.1.tar.xz |
| Mac with an Intel chip | zig-x86_64-macos-0.17.1.tar.xz |
| Linux on a normal PC | zig-x86_64-linux-0.17.1.tar.xz |
| Linux on ARM (Raspberry Pi 4/5, ARM servers) | zig-aarch64-linux-0.17.1.tar.xz |
x86_64 is the usual Intel/AMD chip, and aarch64 is 64-bit ARM. If you’re not sure, it’s almost always x86_64 on Windows and Linux.
Step 2: Unpack it and add it to your PATH
Section titled “Step 2: Unpack it and add it to your PATH”Unpack the archive somewhere you’ll keep it, for example C:\zig on Windows or ~/zig on macOS and Linux. Inside you’ll find a folder like zig-x86_64-linux-0.17.1 with the zig program (zig.exe on Windows), a lib folder with the standard library and a doc folder with the language reference. Keep them together: zig needs its lib folder next to it.
Next, add that folder to your PATH, the list of folders your terminal searches when you type a command.
Windows: open PowerShell and run this snippet from the official page, with the path changed to where your folder is. (The ; before C: isn’t a typo.)
[Environment]::SetEnvironmentVariable( "Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";C:\zig\zig-x86_64-windows-0.17.1", "User")Close PowerShell and open a new one so it picks up the change.
macOS and Linux: unpack the archive, then add an export line to your shell’s startup file (~/.zshrc on a Mac, usually ~/.bashrc or ~/.profile on Linux):
mkdir -p ~/zigtar -xf zig-x86_64-linux-0.17.1.tar.xz -C ~/zigecho 'export PATH="$HOME/zig/zig-x86_64-linux-0.17.1:$PATH"' >> ~/.bashrcUse your own file name, and ~/.zshrc instead of ~/.bashrc if you’re on a Mac. Then open a new terminal.
Prefer a package manager?
Section titled “Prefer a package manager?”The official page also lists package managers. They’re quick, but they install whatever version they’ve packaged, which may be older or newer than the 0.17.1 this tutorial uses. Homebrew and Scoop had 0.17.1 when this page was checked. Run zig version afterwards to see what you got.
| System | Command |
|---|---|
| Windows (WinGet) | winget install -e --id zig.zig |
| Windows (Chocolatey) | choco install zig |
| Windows (Scoop) | scoop install zig |
| macOS (Homebrew) | brew install zig |
| macOS (MacPorts) | sudo port install zig |
| Linux | Many distributions have a zig package, but it’s often an older or newer version. |
Step 3: Check it worked
Section titled “Step 3: Check it worked”Open a new terminal and ask Zig for its version:
zig versionOutput:
0.17.1If you see 0.17.1, you’re ready. If the terminal says something like command not found or 'zig' is not recognized, the folder isn’t on your PATH yet. Double-check the path you added and open a fresh terminal window.
Step 4: Write your first program
Section titled “Step 4: Write your first program”Make a folder for your practice code, then create a file called hello.zig in it with any text editor:
const std = @import("std");
pub fn main() void { std.debug.print("Hello, Zig!\n", .{});}Run it from a terminal in that folder:
zig run hello.zigOutput:
Hello, Zig!That’s your first Zig program. The first run takes a few seconds because Zig compiles parts of its standard library and saves them in a cache. Later runs are much faster.
Understanding the code
Section titled “Understanding the code”Four lines, and each one matters:
const std = @import("std");loads Zig’s standard library and gives it the namestd. Words that start with@are builtin functions, built into the compiler. You’ll write this line at the top of nearly every file.pub fn main() void {defines a function calledmain. Every Zig program starts running there.pubmakes it visible outside the file (Zig needs that to findmain), andvoidmeans it doesn’t return a value.std.debug.print("Hello, Zig!\n", .{});prints a line.\nis the newline at the end: Zig never adds one for you.- The
.{}at the end is an empty list of values to fill into the text. It’s required, even when there’s nothing to fill in.
The curly braces { } mark where main begins and ends, and each statement ends with a semicolon ;. If you know C, JavaScript or Rust, this looks familiar. Python users: here the braces do what indentation does for you.
Now put some values into the text. {s} is a slot for a string and {d} a slot for a number. The values go inside .{ }, in order:
const std = @import("std");
pub fn main() void { std.debug.print("Hello, {s}!\n", .{"Zig"}); std.debug.print("I am learning {s} {d}.\n", .{ "Zig", 17 }); std.debug.print("2 + 3 = {d}\n", .{2 + 3});}Output:
Hello, Zig!I am learning Zig 17.2 + 3 = 5The lines run from top to bottom. 2 + 3 is worked out first, and {d} prints the result. Zig Format Strings covers every slot type.
Running vs building
Section titled “Running vs building”zig run compiles and runs your file in one step. It’s what you’ll use most while learning. The compiled program is kept in Zig’s cache, not in your folder.
When you want a program you can run again or give to someone, build it with zig build-exe:
zig build-exe hello.zig./helloOutput:
Hello, Zig!zig build-exe creates an executable called hello (on Windows, hello.exe plus a hello.pdb file with debug information). On Windows you run it with .\hello.exe.
| Command | What it does | Use it when |
|---|---|---|
zig run hello.zig |
Compiles and runs right away | You’re writing and testing code |
zig build-exe hello.zig |
Makes an executable file | You want a program to keep or share |
Debug builds and release builds
Section titled “Debug builds and release builds”By default Zig builds in debug mode: fast to compile, full of safety checks, and big. On the Linux test machine, hello came out at about 10 MB. Ask for a release build with -O:
zig build-exe hello.zig -O smallThat same hello shrank to about 130 KB. There are four modes: debug (the default), safe (optimized, keeps the safety checks), fast (fastest, safety checks off) and small (smallest, safety checks off). The optimization mode section of the reference explains each one. While learning, stick with debug: its safety checks catch mistakes that release builds let slip.
When something goes wrong
Section titled “When something goes wrong”Everybody makes typos. Here’s what happens if you misspell print:
const std = @import("std");
pub fn main() void { std.debug.prnt("Hello, Zig!\n", .{});}hello.zig:4:14: error: root source file struct 'debug' has no member named 'prnt' std.debug.prnt("Hello, Zig!\n", .{}); ~~~~~~~~~^~~~~It looks scary at first, but it tells you exactly where to look:
hello.zig:4:14means line 4, column 14 ofhello.zig.has no member named 'prnt'meansstd.debugdoesn’t contain anything calledprnt. (“Root source file struct” is just how Zig talks about a file: every.zigfile is a struct of the things declared in it.)- The line below repeats your code, and the
^points at the exact spot.
You’ll also see a few note: and referenced by: lines under it (left out here), with paths into Zig’s own files. They’re extra context. The useful part is almost always the first error: line.
Here’s another one you’ll meet early, a missing semicolon:
const std = @import("std");
pub fn main() void { std.debug.print("Hello, Zig!\n", .{})}hello.zig:4:42: error: expected ';' after statement std.debug.print("Hello, Zig!\n", .{}) ^The caret points just past the end of the line, where the ; should be.
A real project with zig init
Section titled “A real project with zig init”Single files are perfect for learning, and most of this tutorial uses them. Bigger programs use a project with a build.zig file that describes how to build it. zig init creates one for you:
mkdir hello-worldcd hello-worldzig initOutput:
info: created build.ziginfo: created build.zig.zoninfo: created src/main.ziginfo: created src/root.ziginfo: see `zig build --help` for a menu of optionsThen build and run it with zig build run:
zig build runYou’ll see something like:
All your codebase are belong to us.info: arg: ./zig-out/bin/hello_worldRun `zig build test` to run the tests.(The odd first line is an old internet joke the template uses on purpose.) The finished program lands in zig-out/bin/. You don’t need to understand the generated files yet: Zig Tools & Setup walks through them, and the Build System lesson goes deeper.
Practice
Section titled “Practice”1. Three lines
Section titled “1. Three lines”Change hello.zig so it prints three lines: your name, the sentence I'm learning Zig. and the result of 7 * 6.
Hint: use one std.debug.print per line, end each text with \n, and print the number with {d}.
Show solution
const std = @import("std");
pub fn main() void { std.debug.print("My name is Sam.\n", .{}); std.debug.print("I'm learning Zig.\n", .{}); std.debug.print("{d}\n", .{7 * 6});}Output:
My name is Sam.I'm learning Zig.42Each print runs in order. The last one works out 7 * 6 and puts 42 where {d} is.
2. Build a program called greet
Section titled “2. Build a program called greet”Write greet.zig that prints Hi from a real program!, build it into an executable and run that executable (not with zig run).
Hint: zig build-exe names the program after the file, so greet.zig becomes greet.
Show solution
const std = @import("std");
pub fn main() void { std.debug.print("Hi from a real program!\n", .{});}zig build-exe greet.zig./greetOutput:
Hi from a real program!zig build-exe greet.zig creates greet (or greet.exe on Windows) in the current folder, and ./greet runs it. To pick another name, add --name hello-there.
3. Fix the errors
Section titled “3. Fix the errors”This program has two mistakes. Run it, read the errors and fix them one at a time:
const std = @import("std");
pub fn main() void { std.debug.print("Fixed it!\n", .{}) std.debug.print("{d} errors left\n", .{0});}Hint: start with the first error, then run again.
Show solution
const std = @import("std");
pub fn main() void { std.debug.print("Fixed it!\n", .{}); std.debug.print("{d} errors left\n", .{0});}Output:
Fixed it!0 errors leftThe first line inside main was missing its ;. That was the only real mistake: once it’s fixed, everything compiles. One typo can cause more than one message, which is why you fix the first error first.
- Zig isn’t 1.0 yet, so versions matter: this tutorial uses Zig 0.17.1.
- Installing is download, unpack, add the folder to your PATH. Package managers work too, but may give you a different version.
zig versionchecks the install. Every program starts atpub fn main().std.debug.printprints text;{s}and{d}are slots filled from the.{ }list, and\nends the line.zig run file.zigcompiles and runs;zig build-exe file.zigmakes an executable.-O smalland friends make release builds.- In an error, look at the file, line and column, and fix the first
error:first.
Next up: Zig Tools & Setup, a tour of the zig command and how to set up your editor.
Quick check
Section titled “Quick check”Quick check
Read more
Section titled “Read more”- Getting Started (ziglang.org): the official install guide, with PATH setup and package manager commands.
- Download page: every release for every system, plus release notes for each version.
- Language reference for 0.17.1: the official, versioned description of the whole language, starting with Hello World.
- Zig 0.17.0 release notes: what changed in 0.17 (0.17.1 uses the same notes), useful when older code doesn’t compile.