Created
August 25, 2023 05:03
-
-
Save openhoangnc/cca640102338919497752412e087bfd9 to your computer and use it in GitHub Desktop.
Install ziglang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| release=$(curl -s https://api.github.com/repos/ziglang/zig/releases/latest) | |
| tagName=$(echo $release | grep -o '"tag_name": "[^"]*' | grep -o '[^"]*$') | |
| echo "Latest release is $tagName" | |
| arch=$(uname -m) | |
| if [ "$arch" == "arm64" ] | |
| then | |
| arch="aarch64" | |
| fi | |
| os=$(uname -s | tr '[:upper:]' '[:lower:]') | |
| if [ "$os" == "darwin" ] | |
| then | |
| os="macos" | |
| fi | |
| tarballName="zig-$os-$arch-$tagName" | |
| tarballFile="$tarballName.tar.xz" | |
| tarballLink="https://ziglang.org/download/$tagName/$tarballFile" | |
| tarballDownloadFilePath="/tmp/$tarballFile" | |
| echo "downloading tarball: $tarballLink" | |
| curl -L "$tarballLink" -o "$tarballDownloadFilePath" || exit 1 | |
| echo "cleanup old zig" | |
| rm -rf ~/.zig | |
| echo "extracting $tarballDownloadFilePath to /tmp" | |
| tar xf $tarballDownloadFilePath -C /tmp || exit 1 | |
| echo "moving /tmp/$tarballName to ~/.zig" | |
| mv /tmp/$tarballName ~/.zig || exit 1 | |
| echo "cleanup tarball" | |
| rm $tarballDownloadFilePath | |
| bashPATH=$(bash -c 'echo $PATH') | |
| if [[ "$bashPATH" != *"$HOME/.zig"* ]] | |
| then | |
| echo "export PATH=\$PATH:\$HOME/.zig" >> ~/.bashrc | |
| echo "added ~/.zig to PATH in ~/.bashrc" | |
| fi | |
| if [[ -n $(command -v zsh) ]] | |
| then | |
| zshPATH=$(zsh -c 'echo $PATH') | |
| if [[ "$zshPATH" != *"$HOME/.zig"* ]] | |
| then | |
| echo "export PATH=\$PATH:\$HOME/.zig" >> ~/.zshrc | |
| echo "added ~/.zig to PATH in ~/.zshrc" | |
| fi | |
| fi | |
| if [[ -n $(command -v fish) ]] | |
| then | |
| fishPATH=$(fish -c 'echo $PATH') | |
| if [[ "$fishPATH" != *"$HOME/.zig"* ]] | |
| then | |
| echo "set -gx PATH \$PATH \$HOME/.zig" >> ~/.config/fish/config.fish | |
| echo "added ~/.zig to PATH in ~/.config/fish/config.fish" | |
| fi | |
| fi |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
curl -sSL https://bit.ly/install-zig | sh