Last active
November 4, 2025 18:26
-
-
Save withzombies/2e9d10cf7d198b992644edbf103346a7 to your computer and use it in GitHub Desktop.
colima install script
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 | |
| set -e | |
| # Create unique temp directory and ensure cleanup on exit | |
| TMPDIR=$(mktemp -d) | |
| trap 'rm -rf "$TMPDIR"' EXIT | |
| ARCH="$(uname -m)" # expects 'x86_64' or 'arm64' | |
| # Map architecture for Docker Compose and Docker CLI (use aarch64 instead of arm64) | |
| COMPOSE_ARCH=$([ "$ARCH" = "arm64" ] && echo "aarch64" || echo "$ARCH") | |
| DOCKER_ARCH=$([ "$ARCH" = "arm64" ] && echo "aarch64" || echo "x86_64") | |
| # Buildx uses amd64 instead of x86_64, but arm64 as-is | |
| BUILDX_ARCH=$([ "$ARCH" = "x86_64" ] && echo "amd64" || echo "$ARCH") | |
| echo "Fetching download URLs..." | |
| COLIMA_URL=$(curl -s "https://api.github.com/repos/abiosoft/colima/releases/latest" | grep browser_download_url | grep "Darwin" | grep "$ARCH" | head -1 | cut -d '"' -f 4) | |
| LIMA_URL=$(curl -s "https://api.github.com/repos/lima-vm/lima/releases/latest" | grep browser_download_url | grep "Darwin" | grep "$ARCH" | grep 'tar.gz' | head -1 | cut -d '"' -f 4) | |
| # Always get latest Docker CLI (don't skip if already installed) | |
| DOCKER_VERSION=$(curl -s "https://download.docker.com/mac/static/stable/$DOCKER_ARCH/" | grep -o 'docker-[0-9.]*\.tgz' | sort -V | tail -1) | |
| DOCKER_CLI_URL="https://download.docker.com/mac/static/stable/$DOCKER_ARCH/$DOCKER_VERSION" | |
| COMPOSE_URL=$(curl -s "https://api.github.com/repos/docker/compose/releases/latest" | grep browser_download_url | grep "darwin-$COMPOSE_ARCH" | grep -v ".sha256" | grep -v ".json" | head -1 | cut -d '"' -f 4) | |
| # Fix: Use mapped architecture and exclude json files. Exclude amd64 when searching for arm64. | |
| if [ "$BUILDX_ARCH" = "arm64" ]; then | |
| BUILDX_URL=$(curl -s "https://api.github.com/repos/docker/buildx/releases/latest" | grep browser_download_url | grep "darwin-$BUILDX_ARCH" | grep -v "amd64" | grep -v ".json" | head -1 | cut -d '"' -f 4) | |
| else | |
| BUILDX_URL=$(curl -s "https://api.github.com/repos/docker/buildx/releases/latest" | grep browser_download_url | grep "darwin-$BUILDX_ARCH" | grep -v ".json" | head -1 | cut -d '"' -f 4) | |
| fi | |
| # Validate all URLs were retrieved successfully | |
| if [ -z "$COLIMA_URL" ]; then | |
| echo "Error: Failed to retrieve Colima download URL" | |
| exit 1 | |
| fi | |
| if [ -z "$LIMA_URL" ]; then | |
| echo "Error: Failed to retrieve Lima download URL" | |
| exit 1 | |
| fi | |
| if [ -z "$DOCKER_CLI_URL" ]; then | |
| echo "Error: Failed to retrieve Docker CLI download URL" | |
| exit 1 | |
| fi | |
| if [ -z "$COMPOSE_URL" ]; then | |
| echo "Error: Failed to retrieve Docker Compose download URL" | |
| exit 1 | |
| fi | |
| if [ -z "$BUILDX_URL" ]; then | |
| echo "Error: Failed to retrieve Docker Buildx download URL" | |
| exit 1 | |
| fi | |
| echo "All download URLs retrieved successfully" | |
| echo "Colima: $COLIMA_URL" | |
| echo "Lima: $LIMA_URL" | |
| echo "Docker CLI: $DOCKER_CLI_URL" | |
| echo "Docker Compose: $COMPOSE_URL" | |
| echo "Docker Buildx: $BUILDX_URL" | |
| echo "" | |
| cd "$TMPDIR" | |
| echo "Downloading Colima..." | |
| curl -L "$COLIMA_URL" -o colima | |
| if [ ! -f colima ] || [ ! -s colima ]; then | |
| echo "Error: Failed to download Colima or file is empty" | |
| exit 1 | |
| fi | |
| chmod +x colima | |
| sudo mv colima /usr/local/bin/ | |
| sudo xattr -d com.apple.quarantine /usr/local/bin/colima || true | |
| echo "Downloading Lima..." | |
| curl -L "$LIMA_URL" -o lima.tar.gz | |
| if [ ! -f lima.tar.gz ] || [ ! -s lima.tar.gz ]; then | |
| echo "Error: Failed to download Lima or file is empty" | |
| exit 1 | |
| fi | |
| tar -xzvf lima.tar.gz | |
| # Verify tar extraction produced expected files | |
| if [ ! -f bin/limactl ]; then | |
| echo "Error: limactl not found after extraction (expected at bin/limactl)" | |
| exit 1 | |
| fi | |
| chmod +x bin/limactl | |
| sudo mv bin/limactl /usr/local/bin/ | |
| sudo xattr -d com.apple.quarantine /usr/local/bin/limactl || true | |
| echo "Downloading Docker CLI..." | |
| curl -L "$DOCKER_CLI_URL" -o docker.tar.gz | |
| if [ ! -f docker.tar.gz ] || [ ! -s docker.tar.gz ]; then | |
| echo "Error: Failed to download Docker CLI or file is empty" | |
| exit 1 | |
| fi | |
| tar -xzf docker.tar.gz | |
| # Verify tar extraction produced expected files | |
| if [ ! -f docker/docker ]; then | |
| echo "Error: docker binary not found after extraction (expected at docker/docker)" | |
| exit 1 | |
| fi | |
| chmod +x docker/docker | |
| sudo mv docker/docker /usr/local/bin/docker | |
| sudo xattr -d com.apple.quarantine /usr/local/bin/docker || true | |
| echo "Downloading Docker Compose..." | |
| curl -L "$COMPOSE_URL" -o docker-compose | |
| if [ ! -f docker-compose ] || [ ! -s docker-compose ]; then | |
| echo "Error: Failed to download Docker Compose or file is empty" | |
| exit 1 | |
| fi | |
| chmod +x docker-compose | |
| # Install as a Docker CLI plugin to enable 'docker compose' command | |
| sudo mkdir -p /usr/local/lib/docker/cli-plugins | |
| sudo mv docker-compose /usr/local/lib/docker/cli-plugins/docker-compose | |
| sudo xattr -d com.apple.quarantine /usr/local/lib/docker/cli-plugins/docker-compose || true | |
| echo "Downloading Docker Buildx plugin..." | |
| sudo mkdir -p /usr/local/lib/docker/cli-plugins | |
| curl -L "$BUILDX_URL" -o buildx | |
| if [ ! -f buildx ] || [ ! -s buildx ]; then | |
| echo "Error: Failed to download Docker Buildx or file is empty" | |
| exit 1 | |
| fi | |
| chmod +x buildx | |
| sudo mv buildx /usr/local/lib/docker/cli-plugins/docker-buildx | |
| sudo xattr -d com.apple.quarantine /usr/local/lib/docker/cli-plugins/docker-buildx || true | |
| echo "" | |
| echo "Configuring BuildKit..." | |
| # Enable Docker BuildKit by default | |
| SHELL_CONFIG="" | |
| if [ -f "$HOME/.zshrc" ]; then | |
| SHELL_CONFIG="$HOME/.zshrc" | |
| elif [ -f "$HOME/.bashrc" ]; then | |
| SHELL_CONFIG="$HOME/.bashrc" | |
| fi | |
| if [ -n "$SHELL_CONFIG" ]; then | |
| # Check if DOCKER_BUILDKIT is already set | |
| if ! grep -q "DOCKER_BUILDKIT" "$SHELL_CONFIG"; then | |
| echo "" >> "$SHELL_CONFIG" | |
| echo "# Enable Docker BuildKit" >> "$SHELL_CONFIG" | |
| echo "export DOCKER_BUILDKIT=1" >> "$SHELL_CONFIG" | |
| echo "export COMPOSE_DOCKER_CLI_BUILD=1" >> "$SHELL_CONFIG" | |
| echo "Added BuildKit environment variables to $SHELL_CONFIG" | |
| else | |
| echo "BuildKit environment variables already configured in $SHELL_CONFIG" | |
| fi | |
| fi | |
| # Set BuildKit for current session | |
| export DOCKER_BUILDKIT=1 | |
| export COMPOSE_DOCKER_CLI_BUILD=1 | |
| echo "" | |
| echo "Installation completed successfully!" | |
| echo "" | |
| echo "Installed versions:" | |
| /usr/local/bin/colima version | |
| echo "limactl: $(/usr/local/bin/limactl --version)" | |
| /usr/local/bin/docker --version | |
| echo "docker compose: $(/usr/local/lib/docker/cli-plugins/docker-compose version --short)" | |
| echo "docker buildx: $(/usr/local/lib/docker/cli-plugins/docker-buildx version)" | |
| echo "" | |
| echo "Configuration:" | |
| echo "- Docker Compose installed as CLI plugin (use 'docker compose')" | |
| echo "- Docker BuildKit enabled by default" | |
| echo "- Buildx plugin available (use 'docker buildx')" | |
| echo "" | |
| echo "To start Colima:" | |
| echo " colima start" | |
| echo "" | |
| echo "Note: Restart your shell or run 'source $SHELL_CONFIG' to load BuildKit environment variables" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment