Created
November 6, 2025 12:23
-
-
Save kakilangit/be1f162a4e94eeb2a625814b187bd0d2 to your computer and use it in GitHub Desktop.
Install Zig MacOS
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
| #!/bin/bash | |
| # Zig Installation Script for macOS | |
| # Usage: ./install-zig.sh [version] | |
| # Example: ./install-zig.sh 0.16.0-dev.1234+74900e938 | |
| set -e | |
| # Configuration | |
| ZIG_VERSION="${1:-0.16.0-dev.1234+74900e938}" | |
| ZIG_DIR="$HOME/.zig" | |
| ZIG_BIN_DIR="$ZIG_DIR/bin" | |
| # Auto-detect architecture | |
| if [[ $(uname -m) == "arm64" ]]; then | |
| ARCH="aarch64" | |
| else | |
| ARCH="x86_64" | |
| fi | |
| DOWNLOAD_URL="https://ziglang.org/builds/zig-${ARCH}-macos-${ZIG_VERSION}.tar.xz" | |
| TEMP_DIR=$(mktemp -d) | |
| echo "Installing Zig version: $ZIG_VERSION" | |
| echo "Architecture: $ARCH (auto-detected)" | |
| echo "Download URL: $DOWNLOAD_URL" | |
| # Create .zig directory if it doesn't exist | |
| mkdir -p "$ZIG_DIR" | |
| # Remove existing bin directory contents if not empty | |
| if [ -d "$ZIG_BIN_DIR" ] && [ "$(ls -A "$ZIG_BIN_DIR")" ]; then | |
| echo "Removing existing Zig installation..." | |
| rm -rf "$ZIG_BIN_DIR"/* | |
| fi | |
| # Create bin directory | |
| mkdir -p "$ZIG_BIN_DIR" | |
| echo "Downloading Zig..." | |
| cd "$TEMP_DIR" | |
| curl -L -o "zig.tar.xz" "$DOWNLOAD_URL" | |
| echo "Extracting Zig..." | |
| tar -xf "zig.tar.xz" | |
| # Find the extracted directory (it should be zig-${ARCH}-macos-${ZIG_VERSION}) | |
| ZIG_EXTRACTED_DIR=$(find . -name "zig-${ARCH}-macos-*" -type d | head -n 1) | |
| if [ -z "$ZIG_EXTRACTED_DIR" ]; then | |
| echo "Error: Could not find extracted Zig directory" | |
| exit 1 | |
| fi | |
| echo "Moving Zig to $ZIG_BIN_DIR..." | |
| mv "$ZIG_EXTRACTED_DIR"/* "$ZIG_BIN_DIR/" | |
| # Remove quarantine attribute to allow execution on macOS | |
| echo "Removing quarantine attribute from Zig binary..." | |
| xattr -dr com.apple.quarantine "$ZIG_BIN_DIR/zig" 2>/dev/null || true | |
| # Clean up | |
| rm -rf "$TEMP_DIR" | |
| # Verify installation | |
| if [ -x "$ZIG_BIN_DIR/zig" ]; then | |
| echo "✅ Zig installed successfully!" | |
| echo "Zig binary location: $ZIG_BIN_DIR/zig" | |
| echo "" | |
| echo "To use Zig, add the following to your shell profile (~/.zshrc, ~/.bashrc, etc.):" | |
| echo "export PATH=\"$ZIG_BIN_DIR:\$PATH\"" | |
| echo "" | |
| echo "Or run directly: $ZIG_BIN_DIR/zig version" | |
| # Try to show version | |
| "$ZIG_BIN_DIR/zig" version || echo "Note: You may need to add $ZIG_BIN_DIR to your PATH" | |
| else | |
| echo "❌ Installation failed: Zig binary not found or not executable" | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment