To install Zig on Ubuntu 26.04 or 24.04, download the official Linux archive, extract it to /opt/zig and link its executable into your command path. This guide uses Zig 0.17.1, the current stable release, and also shows the Snap alternative.
Zig is a programming language and toolchain for building applications and working with C code. Ubuntu 24.04 does not provide Zig through its standard APT repositories; Ubuntu 26.04 provides older 0.14/0.15 packages. The official archive gives you the same compiler version on both. If a step fails, leave a comment or contact us.
Before you begin
Use Ubuntu 26.04 or 24.04, a Bash terminal, internet access and an account with sudo access.
The archive instructions support Intel/AMD 64-bit (x86_64) and ARM64 (aarch64). Check your architecture before downloading.
You need tar, xz-utils and an HTTPS downloader such as curl or wget. The commands below install and use curl, plus ca-certificates.
Choose one installation method. Use sudo for system packages and /opt, but run Zig projects as your normal user.
Keep the entire extracted Zig bundle, including its lib directory. Moving only the executable can break the installation.
Open a terminal with Ctrl+Alt+T on Ubuntu Desktop:
Ubuntu terminal
cat /etc/os-release
uname -m
type -a zig
Expect x86_64 on most Intel/AMD computers or aarch64 on ARM64. A missing Zig command is normal on a new installation. If Zig already exists, check zig version and identify its installation method before adding another copy.
Step 2: Install the archive tools
Refresh the package list, then install the tools used below:
Ubuntu terminal
sudo apt update
sudo apt install curl ca-certificates tar xz-utils
Review APT’s proposed changes. These tools download and unpack the prebuilt compiler; you do not need to build Zig from source.
Step 3: Download the correct archive
Keep this and the next steps in the same Bash terminal. This selects the matching archive and records its published SHA-256 checksum:
Ubuntu terminal
zig_version=0.17.1
zig_select_arch() {
case "$(uname -m)" in
x86_64)
zig_arch=x86_64
zig_sha=3581863e3cbcfd0fce0efc682ce7e9e93da96668a977791d356a26d2a7e9b17a
;;
aarch64)
zig_arch=aarch64
zig_sha=a1546d5646eb184437918d6635ca6b762a0e889eac09cef720ee7a1ed3fe7795
;;
*) printf 'Use the Zig download page for this architecture.\n'; return 1 ;;
esac
}
zig_select_arch &&
zig_file="zig-${zig_arch}-linux-${zig_version}.tar.xz" &&
zig_setup_dir=$(mktemp -d) &&
curl --fail --location --proto '=https' --tlsv1.2 \
"https://ziglang.org/download/${zig_version}/${zig_file}" \
--output "$zig_setup_dir/$zig_file"
For x86_64, the URL is https://ziglang.org/download/0.17.1/zig-x86_64-linux-0.17.1.tar.xz. The order is zig-architecture-linux-version. Use the official download page for other architectures. Stop if the download fails.
Step 4: Verify the download
Check the downloaded bytes against the checksum for your selected architecture:
Expect the archive path followed by OK. If it reports a mismatch, do not extract or run it. Download it again and compare the release details with the official download index. This detects damaged or mismatched downloads; Zig also publishes Minisign signatures for independent signature verification.
Step 5: Extract into /opt/zig
This creates a new directory and refuses to reuse an existing /opt/zig. If it already exists, stop and use the update section after identifying the installation:
Ubuntu terminal
sudo mkdir /opt/zig &&
sudo tar -xJf "$zig_setup_dir/$zig_file" \
--strip-components=1 --no-same-owner -C /opt/zig &&
/opt/zig/zig version
Expect 0.17.1. The strip option removes the archive’s outer directory, so the executable is /opt/zig/zig, with its libraries beside it. If extraction fails after the directory was created, do not continue to the symlink step; use the failed-extraction advice below.
Step 6: Make Zig available in your terminal
Create the command directory if needed and add a symlink. The ln command deliberately avoids -f, so it will refuse to replace an existing file:
Expect 0.17.1 and /usr/local/bin/zig. This links to a stable location, so replacing /opt/zig later does not require another .bashrc edit. If the path differs, check the PATH troubleshooting section. You can now skip to the project examples; Snap is an alternative.
2. Alternative: install Zig with Snap
Choose this instead of the archive when you want Snap-managed updates. The Zig Snap is published by Jay Petacat, rather than the Zig Software Foundation. Its beta channel carries tagged stable Zig releases; edge carries development builds. The beta channel offered 0.17.1 for amd64 and arm64 when checked on 11 November 2026, but channels can move.
Step 1: Check Snap and the offered version
Check the channel before installing:
Ubuntu terminal
snap version
snap info zig
Under channels, inspect latest/beta and its version. If snap is missing, set up snapd on Ubuntu first. Classic confinement allows broader access to your system than a strictly confined Snap; install only if you trust its publisher.
Step 2: Install and verify the Snap
Do not also install the archive unless you deliberately manage separate versions:
Ubuntu terminal
sudo snap install zig --classic --beta
hash -r
zig version
type -a zig
Snap installs whichever version its beta channel currently offers, not a permanently pinned 0.17.1. If /snap/bin is missing from PATH after enabling snapd, sign out and back in. Use the official archive when you need the specific version in this guide.
3. Why APT differs on Ubuntu 26.04 and 24.04
Ubuntu 24.04’s standard repositories do not contain the Zig compiler. On Ubuntu 26.04, the zig package selects the older 0.14 toolchain, and versioned 0.14/0.15 packages are available in Universe. These are useful for projects that require those versions, but they do not supply 0.17.1.
Ubuntu terminal
apt-cache policy zig zig0.14 zig0.15
Run this after apt update to see the candidates available from your enabled repositories. A missing candidate may reflect disabled Universe or your architecture. Do not add Ubuntu 26.04 repositories to 24.04 to obtain Zig. Use the official archive for 0.17.1 on either release, or inspect Snap’s current beta channel. The examples below target 0.17.1; older Zig APIs can differ.
4. Create a project with zig init
Step 1: Create an empty practice project
Use a new directory so the starter files cannot overwrite your work:
Ubuntu terminal
zig_project_dir=$(mktemp -d "$HOME/zig-project.XXXXXX") &&
cd "$zig_project_dir" &&
zig init
Zig creates a build.zig build script, build.zig.zon package metadata and starter source files under src. Run pwd and keep the path so you can return to the project.
Step 2: Build and run the starter
From that project directory, run:
Ubuntu terminal
zig build run
This compiles and runs the generated application. The starter prints a welcome message, including the line below; extra guidance may also appear. The first compilation can take longer while Zig prepares its cache.
All your codebase are belong to us.
Step 3: Run the generated tests
Still inside the project:
Ubuntu terminal
zig build test
A successful run exits without a build failure. This tests the generated starter, not every future program. Keep build.zig, build.zig.zon and src with your project. Zig creates build caches as needed; do not edit those as source files.
The official getting-started guide explains the starter workflow. Review unfamiliar build scripts and source code before running someone else’s project: building can execute code.
5. Run a single Zig file
Step 1: Write hello.zig
This separate exercise needs no build.zig. Create another new directory, then write a small program:
Ubuntu terminal
zig_hello_dir=$(mktemp -d "$HOME/zig-hello.XXXXXX") &&
cd "$zig_hello_dir" &&
cat > hello.zig <<'ZIG'
const std = @import("std");
pub fn main() void {
std.debug.print("Hello from Zig on Ubuntu!\n", .{});
}
ZIG
The command writes hello.zig only inside the new practice directory. std.debug.print sends this demonstration message to standard error, which is normally visible in your terminal. It is useful for a quick check, rather than a model for production standard-output handling.
Step 2: Compile and run in one command
In the same directory:
Ubuntu terminal
zig run hello.zig
Zig compiles the source and immediately runs it. Expect:
Hello from Zig on Ubuntu!
Step 3: Optionally keep an executable
To create a reusable binary instead:
Ubuntu terminal
zig build-exe hello.zig -femit-bin=hello
./hello
This writes a hello executable into the practice directory. It prints the same message. Run these commands without sudo. Language and standard-library APIs change between Zig releases, so use the 0.17.1 language reference for this compiler.
6. Update Zig without changing your command path
For the archive method, download and verify the chosen release first, following the earlier architecture and checksum steps. Match the checksum to that exact version; do not change only the version variable. Updating Zig can require source or build-script changes, so keep the working compiler until your projects pass.
Step 1: Prepare a separate installation
After verifying the new archive, extract into an unused staging directory:
Ubuntu terminal
sudo mkdir /opt/zig-next &&
sudo tar -xJf "$zig_setup_dir/$zig_file" \
--strip-components=1 --no-same-owner -C /opt/zig-next &&
/opt/zig-next/zig version
If /opt/zig-next already exists, stop and inspect it. Do not extract a new release over an old bundle: files removed by the new release could remain behind. Run /opt/zig-next/zig build test and /opt/zig-next/zig build run from each project before switching.
Step 2: Switch while keeping the old compiler
Close builds using /opt/zig first. This refuses to proceed when a previous backup already exists:
Ubuntu terminal
if [ -e /opt/zig-previous ] || [ -L /opt/zig-previous ]; then
printf 'Inspect /opt/zig-previous before updating.\n'
else
sudo mv -T /opt/zig /opt/zig-previous &&
sudo mv -T /opt/zig-next /opt/zig &&
hash -r &&
zig version
fi
The symlink remains /usr/local/bin/zig, pointing to /opt/zig/zig. Keep /opt/zig-previous until your projects work. If the second move fails, restore the directory with sudo mv -T /opt/zig-previous /opt/zig while /opt/zig is absent. For a later rollback after a successful switch, first preserve the new directory under an unused name, then restore the old one.
For Snap, use sudo snap refresh zig --beta, then check zig version and your project tests. Snap normally refreshes automatically. APT does not update an archive installation under /opt/zig.
7. Fix common Zig installation problems
Issue 1: zig is missing or runs the wrong version
Check which executable your shell selects:
Ubuntu terminal
type -a zig
readlink -f /usr/local/bin/zig
/opt/zig/zig version
For the archive route, the link should resolve to /opt/zig/zig. An older APT, Snap or user-directory installation can take priority. Remove or reconfigure it using its own installation method. Run hash -r afterward. If /usr/local/bin is absent from PATH, add export PATH="/usr/local/bin:$PATH" to ~/.bashrc and open a new Bash terminal.
Issue 2: the symlink command says File exists
Do not force the replacement before finding out what owns the path:
Ubuntu terminal
ls -ld /usr/local/bin/zig
readlink /usr/local/bin/zig
If it already points to /opt/zig/zig, no new link is needed. Otherwise identify the old installation and preserve or remove it deliberately. Do not overwrite a package-managed executable in /usr/bin.
Issue 3: extraction failed or Zig cannot find its libraries
Inspect the bundle and archive:
Ubuntu terminal
ls -ld /opt/zig /opt/zig/lib
ls -l /opt/zig/zig
tar -tJf "$zig_setup_dir/$zig_file" | head
Install xz-utils if tar cannot run xz. Re-download after a checksum failure. If this guide created an incomplete /opt/zig, preserve it under an unused name before repeating extraction into a fresh directory. Keep lib beside the executable; link the executable rather than moving it out of the bundle.
Issue 4: Exec format error or unfamiliar API errors
Check architecture and compiler version:
Ubuntu terminal
uname -m
zig version
Exec format error usually means the archive targets a different architecture or operating system. Use a Linux archive matching your machine. Missing standard-library members or incompatible build scripts often indicate code written for a different Zig version. Match the project’s required compiler and its versioned documentation rather than mixing examples from master and stable releases.
8. Uninstall Zig
Step 1: Verify the archive installation paths
These removal commands apply only to the /opt/zig installation created here. Inspect the paths and close running builds:
Ubuntu terminal
ls -ld /opt/zig /usr/local/bin/zig
readlink /usr/local/bin/zig
Continue only when /opt/zig is your Zig bundle and the link points to /opt/zig/zig. Keep any old compiler backup you still need.
Step 2: Remove the link and compiler bundle
This permanently deletes /opt/zig, including anything you have put inside it. Keep project source in your home directory, outside this installation folder:
Ubuntu terminal
if [ "$(readlink /usr/local/bin/zig)" = /opt/zig/zig ]; then
sudo rm /usr/local/bin/zig &&
sudo rm -r -- /opt/zig &&
hash -r
else
printf 'Link differs; inspect the installation before removing it.\n'
fi
This does not remove your home-directory projects or any separately named backups such as /opt/zig-previous. For a Snap installation, use sudo snap remove zig instead. After removal, type -a zig can reveal another installed copy.
9. Frequently asked questions
Do I need GCC to run these Zig examples?
No. The official prebuilt Zig bundle includes the compiler and standard library needed for these examples. Projects that depend on external C libraries or system tools can have additional requirements.
Should I use sudo zig build?
No. Run project commands as your normal user. Use sudo only for system packages and the installation directories in this guide. Building as root can leave root-owned cache or output files in your project.
What is the difference between zig run and zig build run?
zig run hello.zig compiles and runs one source file directly. zig build run invokes the run step defined by a project build.zig file, such as the one created by zig init. A custom project must define that step itself.
Can I keep more than one Zig version?
Yes. Keep each complete bundle in a separate directory and call its executable by full path. Use the compiler version required by each project. Changing a symlink changes the default command; it does not update source code for a different Zig API.
Why keep the lib folder next to Zig?
The compiler uses files from its bundled lib directory. Keep the extracted bundle together and add its directory to PATH or link to its executable. Copying only the executable can prevent Zig from locating its libraries.