Speeding Up Spack Installs with the Build Cache
Learn how Spack’s build cache stores pre‑built binaries keyed by a spec hash, letting you reuse identical builds across nodes and cut install times—plus the limits you need to watch.
27 Jul 2025, 08:17 UTC

Problem: Repeated recompilation wastes time in HPC workflows
When you spin up a new compute node or share a Spack installation across a cluster, each spack install starts from source. Even if the same package, compiler, and options were used just hours ago, Spack will rebuild everything unless you tell it to reuse existing binaries. This can add minutes—or hours—to setup time, especially for large scientific stacks.
Thesis: Spack’s build cache lets you store and reuse pre‑built binaries safely, cutting install time when the software stack matches exactly.
How the cache works
Spack computes a hash that includes the package spec, compiler version, target architecture, and any variant flags. If that hash matches an entry in the cache, Spack downloads the corresponding tarball, extracts it, and marks the package as installed—no compilation step occurs. The cache is simply a collection of tarballs indexed by those hashes.
Setting up a shared cache
- Create a local cache on a node that has internet access and a working Spack environment:
The# Run on a login or build node where you have write access to $SPACK_ROOT spack buildcache create -a-aflag adds all installed packages to the cache. The command writes tarballs to$SPACK_ROOT/var/spack/build_cacheby default. - Push the cache to a shared location that all cluster nodes can read (NFS, Lustre, or an S3 bucket). You need write permission to the destination:
Replacespack buildcache push -d /shared/spack-cache/shared/spack-cachewith your actual shared path or S3 URL (e.g.,s3://my-bucket/spack-cache). - Pull the cache on a compute node before installing:
This populates the node’s local build‑cache directory with the tarballs. No special privileges are needed beyond read access to the shared location.spack buildcache pull -d /shared/spack-cache
Worked example: installing zlib via the cache
Assume you have a fresh compute node with Spack bootstrapped but no packages installed.
- Pull the shared cache (as shown above).
- Install zlib, letting Spack decide whether to use a cached binary:
If the spec hash of the requested zlib matches a tarball in the cache, Spack will unpack it and finish in seconds.spack install zlib - Verify that the binary came from the cache. One way is to compare the spec hash before and after the install:
If the hash matches the one you saw when you originally created the cache (you can checkspack spec -l zlink # shows the concrete spec and its hash spack find --paths zlib # shows where the files livespack buildcache liston the source node), the package was reused. - As a sanity check, temporarily disable the cache and reinstall; you should notice a longer build time:
The forced rebuild confirms that the cache was active in the first run.spack config set build_cache:false spack install zlib --force spack config unset build_cache
Trade‑offs and limitations
- Portability constraints: Cached binaries are only usable on nodes that share the same CPU architecture, OS version, and ABI. Moving a cache from an x86_64 Linux node to an ARM or a different glibc version will cause Spack to fall back to a source build.
- External system dependencies: If a package links against externally provided libraries (e.g., an MPI implementation) that differ between systems, the cached binary may run incorrectly or fail at runtime.
- No automatic security updates: The cache does not track patches to underlying system libraries. You must regenerate and push new tarballs after applying security fixes.
Practical way to check the result
After pulling the cache and installing a package, run:
spack find --loaded <package>
If the output shows the package as loaded and the version matches what you expect, the install succeeded. Then compare the install time with a baseline source build (e.g., by timing spack install --no-cache <package>). A significant reduction indicates the cache is working.
Actionable closing
Start small: pick a frequently used dependency (like zlib or openmpi), create a cache on your build node, push it to a shared filesystem, and pull it on a test node. Verify reuse with the spec‑hash check, then roll the pattern out to your entire stack. Keep an eye on architecture homogeneity and external library versions, and refresh the cache whenever you apply system‑level patches. With those habits in place, the Spack build cache can turn repetitive compiles into a quick download, freeing up cycles for actual science.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.