Skip to content

Instantly share code, notes, and snippets.

@copperlight
Last active November 15, 2021 19:02
Show Gist options
  • Save copperlight/d2a94c3f51da4deefcfbc50254fd953a to your computer and use it in GitHub Desktop.
Save copperlight/d2a94c3f51da4deefcfbc50254fd953a to your computer and use it in GitHub Desktop.
Building Zig on Ubuntu 20.04 LTS
#!/usr/bin/env bash
# https://github.com/ziglang/zig/wiki/Building-Zig-From-Source
set -efx
VERSION="0.7.1"
# if you have a mixed set of clang and llvm versions, then you
# will need to uninstall the previous version for this to work
PACKAGES=(
clang-11
cmake
libclang-11-dev
liblld-11-dev
lld-11
llvm-11
llvm-11-dev
)
sudo apt update
sudo apt install ${PACKAGES[@]}
if [[ ! -d "$HOME/git/github/ziglang/zig" ]]; then
(mkdir -p "$HOME/git/github/ziglang" && cd "$HOME/git/github/ziglang") || exit 1
git clone [email protected]:ziglang/zig.git
fi
cd "$HOME/git/github/ziglang/zig" || exit 1
git checkout "$VERSION"
(mkdir -p build && cd build) || exit 1
cmake .. -DCMAKE_INSTALL_PREFIX="/usr/local/zig/$VERSION" -DCMAKE_BUILD_TYPE=Release
make
sudo make install
[[ ! -d "$HOME/bin" ]] && mkdir -p "$HOME/bin"
ln -s "/usr/local/zig/$VERSION/bin/zig" "$HOME/bin/zig"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment