Skip to content

Installing Zig, and zig init

2 November 2024 ยท Zig 0.13

Zig comes as one archive: the compiler, its standard library, and the libc headers for every target it knows. Unpack it, put the directory on PATH, and zig version answers. There's no installer and nothing else to fetch.

A single file runs directly with zig run hello.zig:

const std = @import("std");

pub fn main() void {
    std.debug.print("Hello, {s}!\n", .{"Zig"});
}

std.debug.print writes to standard error and can't fail, which is why main returns void here. The .{"Zig"} is an anonymous struct holding the arguments, and the format string is checked against them while compiling: a {d} given a string doesn't build.

For anything bigger, zig init lays out a project:

mkdir hello && cd hello
zig init
zig build run
zig build test

That's a build.zig, the build described in Zig itself; a build.zig.zon for the package's name, version and dependencies; and src/, with an executable and a library to start from.