Skip to content

Zig Upgrading Between Versions

Sooner or later you’ll copy a Zig example from a blog post, a Stack Overflow answer or an older project, and it won’t compile. Often the code was fine; it was just written for a different Zig. Zig isn’t 1.0 yet, and every release changes things, sometimes a lot. This page explains why, how to keep a project on one known version, how to move it to a newer one, and the changes from older Zig that beginners run into most often. Every row in the table near the end was checked by compiling the old and the new form on Zig 0.17.1.

Ask the compiler:

Terminal window
zig version
0.17.1

Every lesson on this site was tested with Zig 0.17.1, the newest stable release when we wrote them. When you read any other Zig tutorial, look for the version it was written for. If it doesn’t say, check its date: code from 2024 or early 2025 usually needs changes.

Zig’s authors want to get the language and the standard library right before they promise to keep them stable. Until 1.0, they’d rather fix a design mistake now than live with it forever. The 0.17.0 release notes open the language section with “Language Stability Progress”: since 0.16 they decided on many open language proposals, and they say finishing that work is a requirement before 1.0.

In practice, the breaks come in three sizes:

  • The language itself changes now and then. 0.17 removed the ** operator for arrays and the |err| capture on errdefer, for example.
  • The standard library changes the most. 0.16 moved all I/O to the new std.Io interface; 0.17 renamed @intFromEnum, replaced DebugAllocator, and moved allocPrint.
  • The build system changes too: 0.17 reworked how build.zig runs, so some build scripts need small edits.

That’s the honest cost of using Zig today. Teams that ship Zig code deal with it by pinning one version and upgrading on purpose, a few times a year, instead of whenever someone updates their machine.

Not every change breaks your build right away. There are two stages:

  • Deprecated: the old name still works, but it’s marked for removal. The compiler doesn’t warn you; you’ll see “Deprecated” in the doc comment or the release notes.
  • Removed: the old name is gone and the code doesn’t compile.

This program uses three names that 0.17 deprecated, and it still builds and runs on 0.17.1:

const std = @import("std");
const Level = enum(u8) { low = 1, mid = 5, high = 9 };
pub fn main() void {
const n = @intFromEnum(Level.mid);
const l: Level = @enumFromInt(9);
const pos = std.mem.indexOf(u8, "zig fmt", "fmt");
std.debug.print("{d} {t} {?d}\n", .{ n, l, pos });
}

Output:

5 high 4

Deprecated names are removed in a later release (some of 0.17’s, like builtin.os, are already marked “to be removed in 0.18.0”). So when you upgrade, fix the deprecations too, while the old and new names both work. That makes the next upgrade smaller.

zig fmt doesn’t only format code. When a rename is simple enough, it rewrites the old form for you. Run it on the program above:

Terminal window
zig fmt main.zig

It changed two lines:

const std = @import("std");
const Level = enum(u8) { low = 1, mid = 5, high = 9 };
pub fn main() void {
const n = @backingInt(Level.mid);
const l: Level = @fromBackingInt(@intCast(9));
const pos = std.mem.indexOf(u8, "zig fmt", "fmt");
std.debug.print("{d} {t} {?d}\n", .{ n, l, pos });
}

Output:

5 high 4

@intFromEnum became @backingInt, and @enumFromInt(9) became @fromBackingInt(@intCast(9)). The @intCast is there because @fromBackingInt wants exactly the enum’s integer type (u8); with a plain number like 9 you can drop it. Notice that std.mem.indexOf wasn’t touched: zig fmt only fixes the changes listed as automatic in the release notes, so read the notes for the rest. (The new name is std.mem.find.)

A project made with zig init on 0.17.1 gets this line in build.zig.zon:

.minimum_zig_version = "0.17.1",

It tells people (and tools) which Zig the project is meant for. Keep it up to date when you upgrade.

Be aware of what it doesn’t do: Zig 0.17.1 doesn’t stop you from building with the wrong version. When we set it to "99.0.0", zig build still built and ran the project without a word. And an older Zig just tries and fails on whatever it doesn’t know. Here’s Zig 0.16.0 building a project made by zig init on 0.17.1:

build.zig:114:12: error: no field or member function named 'addPassthruArgs' in 'Build.Step.Run'
run_cmd.addPassthruArgs();
~~~~~~~^~~~~~~~~~~~~~~~

The error is about one method in build.zig, not about versions at all. If you see a strange error in build.zig right after cloning a project, check minimum_zig_version (and the README) first.

You have a few ways to make sure the right Zig runs:

  • Download it yourself from the official download page. Every release is there, including older ones, as an archive you unpack. This is the simplest option, and it’s what you’d do in CI.
  • A version manager, if you work on projects that need different versions. Three community tools exist: anyzig is a zig command that reads minimum_zig_version from the nearest build.zig.zon and runs (downloading if needed) that version; zigup downloads versions and switches the default; zvm does the same with zvm use. They’re community projects, not part of Zig. We checked that they exist and read their READMEs, but we didn’t test them for this page.
  • Your editor. The VS Code Zig extension can install Zig for you, and without a zig.version setting it looks at minimum_zig_version (see Zig Tools & Setup).

Whatever you choose, write the version in your README too. It costs one line and saves the next person an hour.

Every release has long, detailed notes: 0.17.0 (0.17.1 is a bug-fix release with no separate page) and 0.16.0, which introduced std.Io and main(init: std.process.Init). They’re big, but you don’t need to read every word. For an upgrade, these parts matter most:

  • Language Changes: syntax and builtins that were added, changed or removed.
  • Standard Library and its Deprecations list: renamed and removed functions.
  • Build System and Package Management: changes to build.zig and build.zig.zon.
  • zig fmt: what it upgrades for you.

Many entries include a small “before ⬇️ after” example or a diff. Search the page (Ctrl+F) for the name in your error message, like errdefer or allocPrint, and you’ll usually land on the exact fix.

These are the changes beginners hit most when they copy older code. For each row we compiled the old form and the new form on 0.17.1 (and on 0.16.0 to see when it changed). “Removed” means the old form no longer compiles; “deprecated” means it still does, for now.

Old code Zig 0.17.1 Status on 0.17.1
std.io.getStdOut().writer() std.Io.File.stdout().writer(io, &buf), then flush() Removed: std.io is gone, it’s std.Io since 0.16
std.heap.GeneralPurposeAllocator(.{}){} init.gpa in main, or std.heap.SafeAllocator Removed. Its later name, std.heap.DebugAllocator, still compiles but is deprecated
std.ArrayList(T).init(a), list.append(x) var list: std.ArrayList(T) = .empty;, list.append(gpa, x), list.deinit(gpa) Removed: ArrayList doesn’t store an allocator any more
std.fs.cwd() std.Io.Dir.cwd(), and its methods take io Removed (moved in 0.16)
std.process.argsAlloc(a) init.minimal.args.toSlice(arena) Removed
[_]u8{0} ** 4 const row: [4]u8 = @splat(0); Removed in 0.17
@cImport(@cInclude("x.h")) the translate-c package, used from build.zig Removed in 0.17 (deprecated in 0.16)
-O ReleaseFast, builtin.optimize == .ReleaseFast -O fast, builtin.optimize == .fast Renamed in 0.17. The command line still accepts the old names, but == .ReleaseFast in code is an error
builtin.mode builtin.optimize Deprecated
std.fmt.allocPrint(a, fmt, args) a.print(fmt, args) Deprecated
@intFromEnum(x), @enumFromInt(n) @backingInt(x), @fromBackingInt(n) Deprecated; zig fmt rewrites them
std.mem.indexOf(u8, s, "x") std.mem.find(u8, s, "x") Deprecated (renamed in 0.16)
errdefer |err| log(err); handle the error with catch |err| in a small wrapper function Removed in 0.17
async foo(), await frame io.async(foo, .{}), future.await(io) The keywords were removed in 0.15; io.async arrived in 0.16

A few of these deserve a closer look.

Old code that repeats an array with ** gives an error that doesn’t mention ** at all:

const std = @import("std");
pub fn main() void {
const row = [_]u8{0} ** 4;
std.debug.print("{any}\n", .{row});
}
main.zig:4:26: error: binary operator '*' has whitespace on one side, but not the other
const row = [_]u8{0} ** 4;
^

Since ** no longer exists, Zig reads it as two * signs. Use @splat, which fills an array with one value. The type of the result comes from the variable:

const std = @import("std");
pub fn main() void {
const row: [4]u8 = @splat(0);
const dashes: [10]u8 = @splat('-');
std.debug.print("{any}\n{s}\n", .{ row, &dashes });
}

Output:

{ 0, 0, 0, 0 }
----------

errdefer |err| used to let you look at the error on the way out, usually to log it. In 0.17 the capture is gone:

const std = @import("std");
fn loadConfig(path: []const u8) !void {
errdefer |err| std.debug.print("loading {s} failed: {t}\n", .{ path, err });
if (path.len > 0) return error.FileNotFound;
}
pub fn main() void {
loadConfig("app.conf") catch {};
}
main.zig:4:14: error: expected block or expression, found '|'
errdefer |err| std.debug.print("loading {s} failed: {t}\n", .{ path, err });
^

The fix the release notes suggest: split the function in two, and handle the error with catch in the outer one:

const std = @import("std");
fn loadConfig(path: []const u8) !void {
loadConfigInner(path) catch |err| {
std.debug.print("loading {s} failed: {t}\n", .{ path, err });
return err;
};
}
fn loadConfigInner(path: []const u8) !void {
_ = path;
return error.FileNotFound;
}
pub fn main() void {
loadConfig("app.conf") catch {};
}

Output:

loading app.conf failed: FileNotFound

Plain errdefer without a capture still works exactly as before. See Zig Errdefer.

The four build modes were renamed in 0.17: Debug, ReleaseSafe, ReleaseFast and ReleaseSmall are now debug, safe, fast and small. zig build -Doptimize=ReleaseFast and -O ReleaseFast still work, so old scripts keep running. But code that compares the mode, like if (builtin.optimize == .ReleaseFast), fails with no field named 'ReleaseFast' in enum 'lang.Optimize'. Change it to .fast. See Zig Build Modes.

Here’s a routine that works for a small project:

  1. Commit everything, so you can see what changed and go back if you need to.
  2. Read the release notes for every version you’re skipping, at least the headings above.
  3. Install the new Zig next to the old one (a separate folder, or a version manager).
  4. Run zig fmt . to apply the automatic fixes.
  5. Run zig build (or zig build test) and fix the errors one at a time. Zig often stops at the first missing name in a file, and the next error only shows up after you fix it. Search the release notes for each name.
  6. Fix the deprecations too, while you’re there.
  7. Check your dependencies. A package from build.zig.zon may not support the new Zig yet; look at its minimum_zig_version and its releases. See Zig Packages & Dependencies.
  8. Run all the tests, then update minimum_zig_version and your README, and commit.

If a big project has a lot to change, upgrade one version at a time (0.15 to 0.16, then 0.16 to 0.17) and use each version’s notes. Jumping several versions at once mixes up changes from different releases.

This program was written for an older Zig. Make it work on 0.17.1, printing 2 items: { 10, 20 } to stdout.

const std = @import("std");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var list = std.ArrayList(u32).init(allocator);
defer list.deinit();
try list.append(10);
try list.append(20);
const stdout = std.io.getStdOut().writer();
try stdout.print("{d} items: {any}\n", .{ list.items.len, list.items });
}

On 0.17.1, the first error is:

main.zig:4:23: error: root source file struct 'heap' has no member named 'GeneralPurposeAllocator'
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

Hint: three rows of the table apply. main can take init: std.process.Init, which gives you init.gpa and init.io.

Show solution
const std = @import("std");
pub fn main(init: std.process.Init) !void {
const gpa = init.gpa;
var list: std.ArrayList(u32) = .empty;
defer list.deinit(gpa);
try list.append(gpa, 10);
try list.append(gpa, 20);
var buf: [256]u8 = undefined;
var stdout = std.Io.File.stdout().writer(init.io, &buf);
const out = &stdout.interface;
try out.print("{d} items: {any}\n", .{ list.items.len, list.items });
try out.flush();
}

Output:

2 items: { 10, 20 }

init.gpa replaces the hand-made allocator (and still reports leaks in debug builds), the ArrayList starts as .empty and gets the allocator on each call, and stdout goes through std.Io with a buffer and a flush. See Zig Main & Init and Zig ArrayList.

This program compiles on 0.17.1, but it uses three deprecated names. Replace them with the 0.17 names.

const std = @import("std");
const builtin = @import("builtin");
pub fn main() !void {
const a = std.heap.page_allocator;
const msg = try std.fmt.allocPrint(a, "built in {t} mode", .{builtin.mode});
defer a.free(msg);
const at = std.mem.indexOf(u8, msg, "mode").?;
std.debug.print("{s} ({d})\n", .{ msg, at });
}

Hint: check the table: one is about formatting, one about build modes, one about searching.

Show solution
const std = @import("std");
const builtin = @import("builtin");
pub fn main() !void {
const a = std.heap.page_allocator;
const msg = try a.print("built in {t} mode", .{builtin.optimize});
defer a.free(msg);
const at = std.mem.find(u8, msg, "mode").?;
std.debug.print("{s} ({d})\n", .{ msg, at });
}

Output:

built in debug mode (15)

std.fmt.allocPrint(a, ...) became a.print(...), builtin.mode became builtin.optimize, and std.mem.indexOf became std.mem.find. The output is the same, but the next Zig release won’t break this code over these names.

  • Zig is pre-1.0: every release can change the language, the standard library and the build system.
  • Changes are deprecated first (still compile) and removed later (don’t). Fix deprecations while both names work.
  • zig fmt applies some fixes for you, like @intFromEnum → @backingInt. Run it first.
  • Write the version in minimum_zig_version and your README, but know that 0.17.1 doesn’t enforce it. Get the right Zig from the download page or a version manager.
  • Read the release notes for each version you skip, and search them for the names in your errors.
  • The big ones from older code: std.Io, init.gpa, unmanaged ArrayList with .empty, @splat instead of **, fast instead of ReleaseFast.

Next up: Zig Next Steps, where to go after this tutorial: the official docs, Ziglings, the community and project ideas.

Quick check

1. An old example uses std.mem.indexOf. What happens on Zig 0.17.1?
2. Your build.zig.zon says .minimum_zig_version = "0.18.0" and you run zig build with 0.17.1. What happens?
3. Old code has const zeros = [_]u8{0} ** 8;. What is the 0.17 version?

  • Zig 0.17.0 release notes: every change in the current release, with upgrade examples.
  • Zig 0.16.0 release notes: the std.Io and “Juicy Main” release, where most older code breaks.
  • Download Zig: every release, old and new, plus the development builds.
  • anyzig: a community tool that runs the Zig version a project asks for in build.zig.zon.