title | weight | date | description |
---|---|---|---|
Chapter 0 - Getting Started |
1 |
2023-04-28 11:00:00 -0700 |
Ziglearn - A Guide / Tutorial for the Zig programming language. Install and get started with ziglang here. |
Zig is a general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
Warning: the latest major release is 0.10.1 - Zig is still pre-1.0; usage in production is still not recommended and you may run into compiler bugs.
To follow this guide, we assume you have:
- Prior experience programming
- Some understanding of low-level programming concepts
Knowing a language like C, C++, Rust, Go, Pascal or similar will be helpful for following this guide. You should have an editor, terminal and internet connection available to you. This guide is unofficial and unaffiliated with the Zig Software Foundation, and is designed to be read in order from the start.
This guide assumes you're using a master build of Zig as opposed to the latest major release, which means downloading a binary from the site or compiling from source; the version of Zig in your package manager is likely outdated. This guide does not support Zig 0.10.1.
- Download and extract a prebuilt master binary of Zig from:
https://ziglang.org/download/
-
Add Zig to your path
-
linux, macos, bsd
Add the location of your Zig binary to your
PATH
environment variable. For an installation, addexport PATH=$PATH:~/zig
or similar to your/etc/profile
(system-wide) or$HOME/.profile
. If these changes do not apply immediately, run the line from your shell. -
windows
a) System wide (admin powershell)
[Environment]::SetEnvironmentVariable( "Path", [Environment]::GetEnvironmentVariable("Path", "Machine") + ";C:\your-path\zig-windows-x86_64-your-version", "Machine" )
b) User level (powershell)
[Environment]::SetEnvironmentVariable( "Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";C:\your-path\zig-windows-x86_64-your-version", "User" )
Close your terminal and create a new one.
-
-
Verify your install with
zig version
. The output should look something like
$ zig version
0.11.0-dev.2777+b95cdf0ae
- (optional, third party) For completions and go-to-definition in your editor, install the Zig Language Server from:
https://github.com/zigtools/zls/
- (optional) Join a Zig community.
Create a file called main.zig
, with the following contents:
const std = @import("std");
pub fn main() void {
std.debug.print("Hello, {s}!\n", .{"World"});
}
Use zig run main.zig
to build and run it. In this example Hello, World!
will be written to stderr, and is assumed to never fail.