Skip to content

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.

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.

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.

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.)

Terminal window
[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):

Terminal window
mkdir -p ~/zig
tar -xf zig-x86_64-linux-0.17.1.tar.xz -C ~/zig
echo 'export PATH="$HOME/zig/zig-x86_64-linux-0.17.1:$PATH"' >> ~/.bashrc

Use your own file name, and ~/.zshrc instead of ~/.bashrc if you’re on a Mac. Then open a new terminal.

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.

Open a new terminal and ask Zig for its version:

Terminal window
zig version

Output:

0.17.1

If 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.

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:

Terminal window
zig run hello.zig

Output:

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.

Four lines, and each one matters:

  • const std = @import("std"); loads Zig’s standard library and gives it the name std. 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 called main. Every Zig program starts running there. pub makes it visible outside the file (Zig needs that to find main), and void means it doesn’t return a value.
  • std.debug.print("Hello, Zig!\n", .{}); prints a line. \n is 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 = 5

The lines run from top to bottom. 2 + 3 is worked out first, and {d} prints the result. Zig Format Strings covers every slot type.

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:

Terminal window
zig build-exe hello.zig
./hello

Output:

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

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:

Terminal window
zig build-exe hello.zig -O small

That 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.

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:14 means line 4, column 14 of hello.zig.
  • has no member named 'prnt' means std.debug doesn’t contain anything called prnt. (“Root source file struct” is just how Zig talks about a file: every .zig file 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.

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:

Terminal window
mkdir hello-world
cd hello-world
zig init

Output:

info: created build.zig
info: created build.zig.zon
info: created src/main.zig
info: created src/root.zig
info: see `zig build --help` for a menu of options

Then build and run it with zig build run:

Terminal window
zig build run

You’ll see something like:

All your codebase are belong to us.
info: arg: ./zig-out/bin/hello_world
Run `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.

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.
42

Each print runs in order. The last one works out 7 * 6 and puts 42 where {d} is.

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", .{});
}
Terminal window
zig build-exe greet.zig
./greet

Output:

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.

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 left

The 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 version checks the install. Every program starts at pub fn main().
  • std.debug.print prints text; {s} and {d} are slots filled from the .{ } list, and \n ends the line.
  • zig run file.zig compiles and runs; zig build-exe file.zig makes an executable. -O small and 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

1. Where does every Zig program start running?
2. Which command compiles hello.zig and runs it right away?
3. What does hello.zig:4:14 at the start of an error mean?
4. Why is it worth installing exactly the Zig version a tutorial uses?