Cache directory
By default, Bun stores cached packages in:- macOS/Linux:
~/.bun/install/cache - Windows:
%USERPROFILE%\.bun\install\cache
Custom cache directory
Set a custom cache directory:Via bunfig.toml
Via CLI flag
Via environment variable
Cache behavior
What gets cached
Bun caches:- Tarballs - Downloaded package tarballs from registries
- Extracted packages - Unpacked package contents
- Git repositories - Cloned git dependencies
- Package metadata - Registry responses (manifests)
Cache structure
Cache hits
When installing a package:- Bun checks if the package exists in cache
- If found, uses cached version (no download)
- If not found, downloads and adds to cache
Disabling cache
Disable completely
Via bunfig.toml
Via CLI flag
Bypass cache temporarily
Force re-download packages:Manifest cache
Bun also caches package metadata (manifests) from registries.Manifest cache directory
- macOS/Linux:
~/.bun/install/cache/manifests - Windows:
%USERPROFILE%\.bun\install\cache\manifests
Disable manifest cache
Via bunfig.toml
Via CLI flag
Managing cache
View cache size
Clear cache
View cache location
Configuration
bunfig.toml options
Advanced cache settings
CI/CD caching
GitHub Actions
Cache Bun packages between runs:GitLab CI
Docker
Cache Bun packages in Docker:Cache invalidation
Bun invalidates cache when:- Package version changes
- Package tarball checksum changes
- Registry URL changes
- Bun version changes (major updates)
Manual invalidation
Force cache invalidation:Cache sharing
Multiple projects
The cache is shared across all projects on your machine:Multiple users
Each user has their own cache directory:Troubleshooting
Cache corruption
If you suspect cache corruption:Out of disk space
If cache is too large:Permission errors
If you get permission errors:Slow installs despite cache
If installs are slow even with cache:- Check network connectivity
- Verify cache isn’t disabled
- Check disk I/O performance
- Try clearing and rebuilding cache: