Installing, downloading Zig
Open https://ziglang.org/download/ to see a list of releases. For this book, we’ll be using Zig version 0.15.2. Look for the release titled 0.15.2, and also in the list, find your operating system.
The columns you’ll see are:
OS | Arch | Filename …
For example, if you're on Linux with an x86 64-bit architecture, you’ll identify a link like this: ziglang.org/builds/zig-x86_64-linux.<version>. tar.xz
If you're on Linux or macOS, you can download and extract it into your user's bin folder: ~/bin/ (which is the same as /home/<user>/bin).
|
$ cd ~/bin && \ curl -LO https://ziglang.org/download/0.15.2/zig-x86_64-linux-0.15.2.tar.xz && \ tar -xf zig-x86_64-linux-0.15.2.tar.xz && \ rm zig-x86_64-linux-0.15.2.tar.xz |
You should now have a directory like this:
~/bin/zig-x86_64-linux-0.15.2
To see the contents, you can use the ls command:
|
$ ls ~/bin/zig-x86_64-linux-0.15.2/ |
doc lib LICENSE README.md zig
For now, we’re going to ignore all files except the zig executable. To be able to use zig as a command from any terminal, add this line at the end of your ~/.bashrc or ~/.zshrc file, depending on whether you use Bash or Zsh:
|
$ echo export PATH="$HOME/bin/zig-x86_64-linux-0.15.2:$PATH" >> ~/.bashrc |
After that, if you don’t want to restart the session, reload the file with:
|
$ source ~/.bashrc |
And now you can use Zig from any folder by invoking the zig command.
To see the version we're using:
|
$ zig version |
0.15.2
That’s it. We now have Zig ready to build whatever we can imagine.