By default, zerobrew installs pre-built bottles (binary packages) from Homebrew’s infrastructure for maximum speed. However, you can build packages from source when needed using the --build-from-source flag.
When to Build from Source
Consider building from source when:
- Pre-built bottles are unavailable for your platform
- You need custom compilation flags or optimizations
- You’re debugging package issues
- You want packages optimized for your specific CPU architecture
- A bottle is corrupted or outdated
Building from source is significantly slower than installing bottles. A package that installs in seconds from a bottle may take minutes to build from source.
Basic Usage
Use the -s or --build-from-source flag with zb install:
Output:
Installing Multiple Packages from Source
Build all specified packages from source:
This builds wget, git, and sqlite from source, along with any dependencies.
How Source Builds Work
When you use --build-from-source, zerobrew:
- Downloads the formula definition from
homebrew-core
- Fetches the source tarball or repository
- Compiles the package using Homebrew’s Ruby DSL build instructions
- Installs to zerobrew’s content-addressable store
- Links binaries to your prefix (unless
--no-link is used)
Build Requirements
Building from source requires:
- Compiler toolchain: Xcode Command Line Tools (macOS) or build-essential (Linux)
- Ruby: For executing Homebrew formula build scripts
- Dependencies: Any build-time dependencies the package requires
Combining with Other Flags
Build from source without linking
This builds ffmpeg from source but doesn’t add it to your PATH.
Build and install in one command
Typical installation times:
Complex packages like ffmpeg can take 10-30 minutes to build from source depending on your CPU.
Dependencies
When building from source, all dependencies are also built from source by default. For example:
This also builds dependencies like openssl, curl, pcre2, etc. from source, significantly increasing build time.
Troubleshooting Source Builds
Build fails with compiler error
Ensure you have development tools installed:
Missing build dependencies
If a build fails due to missing dependencies:
The dependency should be auto-installed. If not, install it manually:
Build takes too long
Some packages have many dependencies. Check what will be built:
Consider using bottles instead if available:
Disk space issues
Source builds require temporary disk space for:
- Source code
- Intermediate build artifacts
- Final compiled binaries
Ensure you have several GB of free space for large packages like llvm or gcc.
When Bottles Aren’t Available
If no pre-built bottle exists for your platform, zerobrew automatically falls back to building from source:
Output:
No --build-from-source flag is needed in this case.
Architecture-Specific Builds
Building from source allows optimization for your CPU:
- On Apple Silicon (M1/M2), native ARM64 optimizations
- On Intel, x86_64 optimizations with CPU-specific flags
- On Linux, distribution-specific optimizations
Bottles are pre-built for common architectures and may not be fully optimized for your specific CPU.
Source Code Location
During builds, zerobrew:
- Downloads sources to
$ZEROBREW_ROOT/cache
- Extracts and builds in temporary directories
- Installs to
$ZEROBREW_ROOT/store/<hash>
- Cleans up temporary build artifacts
You can inspect the cache:
zb install <formula> - Install using bottles (default)
zb info <formula> - View package information and dependencies
zb gc - Clean up unused store entries and cache files