Skip to main content

Installing Zig

This guide will help you install Zig on your system. There are multiple ways to get Zig depending on your platform and needs.

Download Pre-built Binaries

The easiest way to get started with Zig is to download pre-built binaries from the official website.
1

Visit the Zig downloads page

Navigate to ziglang.org/download to find the latest release for your platform.
2

Choose your platform

Zig provides pre-built binaries for:
  • Linux (x86_64, aarch64, riscv64, loongarch64, s390x)
  • macOS (x86_64, aarch64)
  • Windows (x86_64, aarch64)
  • FreeBSD (x86_64)
3

Extract the archive

Download and extract the archive to a directory of your choice:
tar xf zig-linux-*.tar.xz
4

Add to PATH

Add the Zig binary to your system PATH:
export PATH=$PATH:/path/to/zig
Add this to your shell’s configuration file (.bashrc, .zshrc, etc.) to make it permanent.

Building from Source

You can build Zig from source for maximum control and to contribute to development.

Prerequisites

Building Zig from source requires:
  • CMake 3.15 or later
  • C and C++ compiler (GCC, Clang, or MSVC)
  • Ninja build system (recommended)
  • LLVM, Clang, and LLD libraries (optional, for LLVM backend)

Build with CMake

1

Clone the repository

git clone https://github.com/ziglang/zig.git
cd zig
2

Create build directory

mkdir build
cd build
3

Configure with CMake

The CMakeLists.txt:1-38 defines the build configuration:
cmake .. \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_INSTALL_PREFIX=/usr/local \
  -GNinja
The default install prefix is stage3 in the build directory. Override with -DCMAKE_INSTALL_PREFIX.
4

Build and install

ninja install
This will create a stage3 build in the installation prefix.

Build with Zig (Bootstrap)

If you already have Zig installed, you can use it to build the latest version:
1

Use zig build

From the source directory:build.zig:16:
zig build
2

Install to prefix

zig build -Doptimize=ReleaseFast --prefix /usr/local

Common Build Options

From build.zig and CMakeLists.txt:
  • -Doptimize=ReleaseFast - Optimize for speed
  • -Doptimize=ReleaseSmall - Optimize for binary size
  • -Doptimize=Debug - Debug build with safety checks
  • -Dtarget=<triple> - Cross-compile for specific target
  • -Dno-lib - Skip copying lib/ files (for development)
  • -Denable-llvm - Enable LLVM backend
  • -DZIG_STATIC=ON - Build static binary (CMake)

Package Managers

Package manager versions may lag behind the latest Zig release. For the newest features, download from ziglang.org or build from source.
brew install zig

Verify Installation

After installation, verify that Zig is properly installed:
1

Check version

zig version
This should output the Zig version, e.g., 0.16.0.
2

Display the Zen of Zig

From main.zig:5641-5655:
zig zen
This displays the Zen of Zig:
 * Communicate intent precisely.
 * Edge cases matter.
 * Favor reading code over writing code.
 * Only one obvious way to do things.
 * Runtime crashes are better than bugs.
 * Compile errors are better than runtime crashes.
 * Incremental improvements.
 * Avoid local maximums.
 * Reduce the amount one must remember.
 * Focus on code rather than style.
 * Resource allocation may fail; resource deallocation must succeed.
 * Memory is a resource.
 * Together we serve the users.
3

View supported targets

zig targets
This shows all compilation targets that Zig supports, including architectures, operating systems, and C ABIs.

Next Steps

Now that you have Zig installed, you’re ready to write your first program!

Quick Start Guide

Learn how to create and build your first Zig program

Build docs developers (and LLMs) love