Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 37 ยท Getting Started

Installing Zig

Install the Zig compiler on Windows, macOS or Linux, check it with zig version, set up an editor with ZLS, and manage multiple Zig versions as a beginner.

Installing Zig is unusually easy. The compiler is a single self-contained download: no installer, no separate linker, no Visual Studio or system C library needed. You unpack an archive, put one folder on your PATH, and you are done.

This lesson covers the installation on every major system, how to verify it, how to pick a version, and how to set up an editor so you get errors and completion while typing.

Pick a version

Zig releases are numbered like 0.15.1. Because the language is pre-1.0, each minor version (0.14, 0.15, 0.16 ...) may change the standard library, and occasionally the language. Two rules keep you out of trouble:

  1. Use the latest tagged release from the download page at ziglang.org/download while learning.
  2. When you read an older tutorial and something does not compile, check the version it targets first. Most breakage is renamed standard library functions, not language changes.

There is also a master (nightly) build, which is what the compiler team develops against. Use it only if a project asks for it.

Windows

  1. Download the x86_64-windows .zip archive for the release.
  2. Extract it to a permanent folder, for example C:\zig.
  3. Add that folder to your PATH (Settings, System, About, Advanced system settings, Environment Variables).
  4. Open a new terminal.

Package managers work as well:

TEXT
winget install zig.zig
scoop install zig

macOS

TEXT
brew install zig

Or download the .tar.xz for your CPU (aarch64-macos for Apple silicon, x86_64-macos for Intel), extract it, and add the folder to your PATH in ~/.zshrc.

Linux

Most distributions package Zig, but often an older version. For the version you want, use the official archive:

TEXT
tar xf zig-x86_64-linux-0.15.1.tar.xz
sudo mv zig-x86_64-linux-0.15.1 /opt/zig
echo 'export PATH="$PATH:/opt/zig"' >> ~/.bashrc

Replace the file name with the one you downloaded. Open a new shell afterwards.

Check the installation

TEXT
zig version

prints the version number, for example 0.15.1. zig env shows where the standard library lives, where the global cache is, and the target your machine reports. If zig is not found, the PATH entry is wrong or the terminal was opened before you changed it.

The folder you add to PATH is the one that contains the file zig (or zig.exe) next to a lib directory. The standard library sources live in that lib folder, and the compiler finds them relative to its own location, so never move zig.exe away from lib.

Managing several versions

Because projects pin different releases, version managers are popular:

  • zigup downloads releases and switches between them.
  • anyzig reads the minimum_zig_version from your project's build.zig.zon and runs the matching compiler automatically.
  • Unpacking each release into its own folder and changing the PATH also works fine.

Your editor

Zig works with any text editor, but the Zig Language Server (ZLS) gives you completion, go to definition, diagnostics and format on save. Install the Zig extension for your editor (Visual Studio Code, Neovim, Zed, Helix, IntelliJ and others all have one). The extension usually downloads a ZLS build that matches your Zig version. Mismatched versions are the most common cause of strange editor errors, so keep them in step.

The formatter is part of the compiler: zig fmt file.zig rewrites a file in the official style, and editors call it on save. Zig's style is not configurable, which means all Zig code looks the same.

Cross-compilation works immediately

Because Zig ships the standard library sources and its own linker, you can build for another system without installing anything:

TEXT
zig build-exe main.zig -target x86_64-windows
zig build-exe main.zig -target aarch64-linux
zig targets

zig targets lists everything the compiler can produce, which is a long list.

Practice: comparing versions

Programs often need to compare version numbers, just like the minimum_zig_version field in a Zig project. This C stand-in parses major.minor.patch and checks it against a minimum.

C Stand-in (C): compare version numbers

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What do you need to install besides the Zig archive to compile Zig programs?

    Zig ships its own compiler front end, linker support and standard library sources.
  2. 2. Which command prints the installed Zig version?

    zig version prints the compiler version string.
  3. 3. What is ZLS?

    ZLS speaks the Language Server Protocol so editors can offer completion and errors.
  4. 4. Why should ZLS match your Zig version?

    ZLS analyzes your code against a specific language and standard library version.

Summary

  • Zig is a single archive: unpack it, add the folder to PATH, run zig version.
  • Use the latest tagged release while learning; expect small changes between 0.x versions.
  • Install the Zig extension (with ZLS) for your editor and keep versions matched.
  • zig fmt formats code, and -target cross-compiles with no extra setup.

Next: Your First Zig Program