Skip to content
Bun
Bun
Advanced Configuration

Global cache

How Bun stores and manages packages in its global cache

Bun stores every package downloaded from the registry in a global cache at ~/.bun/install/cache, or the path set by the BUN_INSTALL_CACHE_DIR environment variable. Packages live in subdirectories named like ${name}@${version}, so multiple versions of a package can be cached.


Minimizing re-downloads

When installing a package, if the cache already contains a version in the range specified by package.json, Bun uses the cached copy instead of downloading it again.


Fast copying

Once a package is downloaded into the cache, Bun still needs to copy those files into node_modules. It uses the fastest syscalls available for this: hardlinks on Linux, clonefile on macOS.


Saving disk space

Since Bun uses hardlinks to “copy” a module into a project’s node_modules directory on Linux and Windows, the contents of the package only exist in a single location on disk, greatly reducing the disk space used by node_modules.

The same applies on macOS, with a caveat. There Bun uses clonefile, which is copy-on-write: the clone occupies no extra disk space, but it counts towards the drive’s limit. Because the copy only happens on write, patching node_modules/* in one project can’t affect other installations.

Was this page helpful?Suggest editsRaise issue