instalacion-configuracion-zig

Install Zig and configure the development environment

  • 5 min

Installing Zig means preparing the compiler, the PATH, and the editor to write and run code. Now that we know why Zig is such an interesting tool, it’s time to get our hands dirty.

Unlike other development environments that require heavy installers or many dependencies, Zig is distributed in a self-contained folder.

Inside we find the compiler executable and its library files. There is no need to run an installer: just unzip the distribution and add it to the PATH.

In this post we will prepare the machine for Zig development and set up VS Code with ZLS (Zig Language Server). You can program without ZLS, of course, but autocompletion and diagnostics will save us a lot of work.

Zig has not yet reached version 1.0 (it is still in 0.x versions). As of this revision, the latest stable version is Zig 0.16.0. To follow the course, it’s best to use a tagged stable version; development builds are useful for trying out new features, but things can change from one day to the next.

Download and install the compiler

There are two ways to install Zig: download the official distribution or use a package manager.

With a package manager

If you already use a package manager, this is usually the most convenient way to keep Zig updated.

On Windows (with Winget or Chocolatey):

winget install -e --id zig.zig
# Or if you use Chocolatey
choco install zig
Copied!

On macOS (with Homebrew):

brew install zig
Copied!

On Linux (with Snap):

snap install zig --classic
Copied!

With the official distribution

This option is useful for having multiple versions of Zig or controlling exactly which one each project uses.

  1. Go to the official Zig download page.
  2. Download the compressed file (.zip or .tar.xz) for your operating system and architecture.
  3. Unzip the folder to a stable location (e.g., C:\zig\ on Windows or ~/zig/ on Linux and macOS).
  4. Add that folder to your system’s PATH.

Why the PATH? The PATH is an environment variable that tells your terminal “where to look” when you type a command. By adding the Zig folder, you can type zig in any console and it will work.

Verifying the installation

Whichever method you choose, open a terminal and type:

zig version
Copied!

If it returns 0.16.0 (or the stable version you installed), the compiler is ready.

The development environment: VS Code and ZLS

Having the compiler is only half the battle. Zig is a modern language and, as such, greatly benefits from good editor support.

Although you can use Vim, Emacs, or any other editor, we will focus on Visual Studio Code, which has very convenient integration.

Install the official extension

In VS Code, go to the extensions marketplace and search for “Zig”.

Install the official Zig Language extension, published by ziglang with the identifier ziglang.vscode-zig. It includes syntax highlighting, formatting, and ZLS integration.

ZLS: the Zig Language Server

ZLS (Zig Language Server) is a tool that runs in the background and analyzes our code in real time. It provides us with:

  • Intelligent autocompletion.
  • Go to definition (Ctrl + Click).
  • Error detection while we type (without needing to compile).
  • Automatic code formatting.

The VS Code extension can install and update Zig and ZLS automatically.

  1. Open any .zig file in VS Code.
  2. If the ZLS installation prompt appears, click Install.
  3. Check in the extension settings which versions of Zig and ZLS it is using.

If you prefer to do it manually:

  1. Download a compatible version of ZLS from its official repository.
  2. In the extension settings, indicate the paths to the Zig and ZLS executables.

Configure VS Code to format on save. In your settings.json:

"[zig]": { "editor.formatOnSave": true }
Copied!

The formatting applied by ZLS matches zig fmt, so the code will maintain the standard style.

Our first “Hello World”

Let’s verify that everything works. Create a new folder for the project and inside it, create a file named main.zig.

Write the following code:

const std = @import("std");

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

It’s okay if the syntax is still unfamiliar; we’ll cover it later. The important thing here is to check if ZLS autocompletes std.debug as you type. If it does, the environment is well configured.

Running the code

In Zig we have a wonderful tool for development: zig run.

This command compiles the program in a temporary folder and runs it immediately, all in one step. It’s perfect for quickly testing things.

Open the terminal in VS Code and run:

zig run main.zig
Copied!

You should see: Hello World from Zig!

Compiling a real executable

To generate an executable (a .exe on Windows or a binary on Linux and macOS), we use:

zig build-exe main.zig
Copied!

This will generate a main.exe or main file in the current folder.

By default, Zig compiles in “Debug” mode (slower, but with safety checks). To get maximum performance we will use zig build-exe main.zig -O ReleaseFast.