How to Install Zig on Ubuntu: The General-Purpose Systems Programming Language

Zig is a general-purpose systems programming language built for writing robust, optimal and reusable software. Positioned as a modern successor to C, it does away with hidden control flow and hidden allocations, swaps macros for compile-time execution (comptime), and treats cross-compilation as a core feature rather than an afterthought.

The catch on Ubuntu is versioning. Zig releases frequently, and the packages in the Ubuntu archive (or in apt as zig) are usually several versions behind β€” old enough that code from the current documentation may not even compile. The manual alternative, downloading tarballs from ziglang.org and wiring up your own PATH, works but leaves you responsible for every upgrade.

The unofficial deb.griffo.io repository provides a prebuilt, current Zig package you install and upgrade with plain apt. Below is the full setup on Ubuntu.

What Makes Zig Special?

  • 🧠 Compile-time execution β€” comptime unifies generics, macros and build-time logic into one mechanism that is just Zig running early.
  • 🌍 Cross-compilation everywhere β€” build for Windows, macOS or ARM Linux from your Ubuntu machine with a single -target.
  • πŸ” No hidden control flow β€” no exceptions and no surprising operator behaviour; the code you read is the code that runs.
  • 🧹 Explicit allocators β€” memory strategy is passed in as a value, making it visible, swappable and testable.
  • πŸ”§ Bundled C/C++ compiler β€” zig cc and zig c++ are Clang-backed and can compile existing C and C++ code.
  • πŸ§ͺ First-class tests β€” write test blocks next to your functions and run them with zig test.
  • πŸ“¦ Self-hosted build system β€” build.zig is Zig, so there is no second language to learn for builds.
  • ⚑ Tunable optimisation β€” pick Debug, ReleaseSafe, ReleaseFast or ReleaseSmall per build.

Why Use the deb.griffo.io Repository?

  • Install and update through APT β€” no manual downloads, no PATH surgery.
  • Automatic dependency management courtesy of Debian-style packaging.
  • Always tracks upstream so you stay on a current Zig release.
  • No source builds and no LLVM compilation on your machine.
  • Works across supported Ubuntu releases β€” Jammy, Noble and newer.

Prerequisites

You will need:

  • An Ubuntu system (Jammy 22.04 LTS, Noble 24.04 LTS, or newer)
  • sudo privileges
  • curl installed (sudo apt install curl if it is not already present)

Step 1: Add the deb.griffo.io Repository

These commands install the repository signing key and add its source list:

# Create the keyrings directory
sudo install -d -m 0755 /etc/apt/keyrings

# Download and install the repository GPG key
curl -fsSL https://deb.griffo.io/EA0F721D231FDD3A0A17B9AC7808B4DD62C41256.asc | sudo gpg --dearmor --yes -o /etc/apt/keyrings/deb.griffo.io.gpg

# Add the repository (auto-detects your distro codename)
echo "deb [signed-by=/etc/apt/keyrings/deb.griffo.io.gpg] https://deb.griffo.io/apt $(lsb_release -sc 2>/dev/null) main" | sudo tee /etc/apt/sources.list.d/deb.griffo.io.list > /dev/null

# Update the package list
sudo apt update

Step by step:

  1. Keyrings directory β€” /etc/apt/keyrings is the recommended home for third-party keys on modern Ubuntu.
  2. GPG key β€” fetched and de-armoured so APT can verify the repository’s packages.
  3. Source list β€” lsb_release -sc fills in your Ubuntu codename (for example noble) automatically.
  4. Update β€” pulls the new package metadata into APT.

Step 2: Update the Package List

If you did not run the last command above, do it now:

sudo apt update

Step 3: Install Zig

sudo apt install zig

APT downloads Zig and any dependencies and installs the current packaged toolchain.

Step 4: Verify the Installation

The version subcommand has no dashes β€” it is zig version:

zig version

Expected output looks like:

0.14.1

To see the compiler’s detected environment (cache paths, target, and so on), run zig env.

Getting Started with Zig

Scaffold a Project

The quickest way in is to let Zig generate a project skeleton for you:

mkdir myapp && cd myapp
zig init

# Compile the project
zig build

# Compile and run
zig build run

# Run tests
zig build test

zig init writes a build.zig, a build.zig.zon dependency manifest and a src/main.zig starter.

Hello, World

If you prefer a single file, create hello.zig:

const std = @import("std");

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

Run it, or build a binary:

# Compile and execute in one go
zig run hello.zig

# Produce a standalone executable
zig build-exe hello.zig
./hello

Cross-Compilation

Zig cross-compiles without any extra toolchains. From Ubuntu you can build for other platforms directly:

# 64-bit Windows
zig build-exe hello.zig -target x86_64-windows

# 64-bit ARM Linux (Raspberry Pi, servers)
zig build-exe hello.zig -target aarch64-linux

# See the full list of supported targets
zig targets | less

Testing Your Code

Tests are part of the language. In math.zig:

const std = @import("std");

pub fn double(x: i32) i32 {
    return x * 2;
}

test "double works" {
    try std.testing.expectEqual(@as(i32, 8), double(4));
}

Then:

zig test math.zig

Zig as a C/C++ Compiler

zig cc behaves like Clang and can even cross-compile C:

# Build a C program
zig cc -o demo demo.c

# Cross-compile the same C for ARM
zig cc -target aarch64-linux -o demo-arm demo.c

Formatting

The formatter ships with the compiler:

# Reformat a file
zig fmt hello.zig

# Verify formatting in CI without editing
zig fmt --check src/

Keeping Zig Updated

Zig upgrades ride along with your normal system updates:

sudo apt update && sudo apt upgrade

Other Tools from deb.griffo.io

The repository carries a whole ecosystem of developer tools for Ubuntu:

  • Helix β€” a post-modern modal editor with built-in LSP, a natural fit for Zig.
  • Zellij β€” a terminal workspace and multiplexer with batteries included.
  • Lazydocker β€” a simple terminal UI for Docker and docker-compose.
  • Yazi β€” a blazing-fast terminal file manager written in Rust.

Troubleshooting

GPG or Key Errors

An NO_PUBKEY or signature error means APT cannot verify the repository. Re-install the key:

sudo install -d -m 0755 /etc/apt/keyrings
curl -fsSL https://deb.griffo.io/EA0F721D231FDD3A0A17B9AC7808B4DD62C41256.asc | sudo gpg --dearmor --yes -o /etc/apt/keyrings/deb.griffo.io.gpg
sudo apt update

Package Not Found

If apt install zig cannot find the package:

  1. Run sudo apt update again β€” the repository has to be indexed first.
  2. Check that your Ubuntu release is supported (Jammy, Noble or newer).
  3. Confirm the codename was detected in the source list:
cat /etc/apt/sources.list.d/deb.griffo.io.list

A Snap or Tarball Zig Is Taking Priority

If zig version reports something unexpected, another install may be first on your PATH β€” commonly a snap or a tarball unpacked into ~/.local/bin. Inspect it:

which zig
type -a zig

Remove the competing copy (for a snap, sudo snap remove zig) and start a fresh shell so the APT-managed binary wins.

Uninstalling

# Remove the Zig package
sudo apt remove zig

# Optionally remove the repository as well
sudo rm -f /etc/apt/sources.list.d/deb.griffo.io.list
sudo rm -f /etc/apt/keyrings/deb.griffo.io.gpg
sudo apt update

Conclusion

Zig pairs a small, explicit systems language with cross-compilation and a bundled C compiler, and deb.griffo.io keeps that toolchain current on Ubuntu without any manual downloads. One apt install gets you going, and every later release arrives through the same apt upgrade you run for everything else.

From embedded targets to replacing a crusty C build, an always up-to-date compiler within a single command makes Zig far more pleasant to live with on Ubuntu.

Resources


Disclaimer: The deb.griffo.io repository is an unofficial community project and is not affiliated with the official Debian or Ubuntu projects, or with the upstream Zig project.