Installation
The best way to download Zig is through the official website. The nightly version of Zig is currently not available through tools like Homebrew. You’ll need to have an internet connection for the download.
Zig is currently unstable (pre 1.0). This means that each release may have breaking changes and guides can quickly become out-of-date. Please be sure to use a nightly version of Zig 0.15 so that the examples in this book compile in your local environment.
Note: Command Line Notation Throughout the book, we’ll use some commands in the terminal. This will be marked by
$
. You don’t need to type the$
character; it’s the command line prompt shown to indicate the start of each command. PowerShell-specific examples will use>
rather than$
.
Installing on macOS
If you’re on macOS, you can download the latest version from the official site . If you are using an Intel-based Mac, download the x86 version. If you are on an ARM-based Mac (M1 or newer), download the aarch64 version.
Next, we can rename the downloaded folder to something like “zig 0.15” and move it to a better location, such as your home (user) folder. We then need to add Zig to our path. If you are not using zsh, add the path to the downloaded Zig folder in your shell of choice. Open your teminal and type the following commands. This assumes your .zshrc
is in your ~
directory.
$ nano .zshrc
Earlier, we moved the downloaded folder to your home directory to make this step simpler. We must write the path to that folder in .zshrc
, replacing <folder-name>
with the name of the folder you downloaded and moved earlier. If you did not place the folder in your home directory, you will also need to substitute $HOME
with the path to the folder.
export PATH="$PATH:$HOME/<folder-name>"
If you edited the file using nano, as shown in the above command, use ctrl + o
to save the file, then tab
or enter
to confirm, and ctrl + x
to exit.
Troubleshooting
To check if you’ve installed everything correctly, run the command:
$ zig version
You should see something like this:
0.15.0-dev.99+c1db72cdb
If you see this information, you have successfully installed Zig! If you see an error like zsh: command not found: zig
, then you likely set up your path incorrectly. Try to follow the exact guide if you made any customizations.
In the next section, we’ll write our first Zig program.