Welcome to our today’s guide on how to install Zig Programming Language on Ubuntu and Debian operating systems. Zig is a general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software. The Zig programming language is developed by the Zig Software Foundation, which is a non-profit corporation founded in 2020 by Andrew Kelley.

Below are some of the key Zig features:

  • A Simple Language: The language focuses on debugging your application rather than debugging your programming language knowledge. There are no hidden control flow, memory allocations and preprocessor/macros.
  • Performance Meets Safety: The Zig language gracefully guides your error handling logic. The Configurable runtime checks help you strike a balance between performance and safety guarantees.
  • Comptime: Has a fresh approach to metaprogramming based on compile-time code execution and lazy evaluation. You can Call any function at compile-time.

Install Zig Programming Language on Ubuntu | Debian

We will use the pre-built OS packages to install Zig Programming Language on Ubuntu | Debian. These packages are available in an APT repository which needs to be added manually.

Import PGP Signing Keys:

sudo apt update
sudo apt install gnupg2
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 379CE192D401AB61

Run the following commands to add Zig APT repository.

Ubuntu:

echo "deb https://dl.bintray.com/dryzig/zig-ubuntu $(lsb_release -sc) main" | sudo tee  /etc/apt/sources.list.d/zig.list

Debian:

echo "deb https://dl.bintray.com/dryzig/zig-debian $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/zig.list

Update APT cache index once the repository is added:

sudo apt update

Once this is done run the commands below to install Zig Programming Language on Ubuntu | Debian:

sudo apt install zig

Expected installation command output:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  zig
0 upgraded, 1 newly installed, 0 to remove and 128 not upgraded.
Need to get 40.5 MB of archives.
After this operation, 228 MB of additional disk space will be used.
Get:1 https://dl.bintray.com/dryzig/zig-ubuntu focal/main amd64 zig amd64 0.6.0-1 [40.5 MB]
Fetched 40.5 MB in 2s (18.5 MB/s)
Selecting previously unselected package zig.
(Reading database ... 63395 files and directories currently installed.)
Preparing to unpack .../archives/zig_0.6.0-1_amd64.deb ...
Unpacking zig (0.6.0-1) ...
Setting up zig (0.6.0-1) ...

Verify the installation of Zig Programming Language on Ubuntu | Debian:

$ zig version
0.6.0

Create a “Hello World” code in a file called main.zig:

cat >main.zig<<EOF
const print = @import("std").debug.warn;

pub fn main() void {
    print("Hello, world!\n", .{});
}
EOF

Use below command to build and run the program:

$ zig run main.zig
Hello, world!

Zig resources:

Similar guides:

Install Swift Programming Language on Ubuntu

Install Julia Programming Language on CentOS

Install Kotlin Programming Language on Linux Mint | Ubuntu