Runtime
Bundler
Package Manager
Test Runner
Guides
Reference
Blog
Install Bun
Package Manager Advanced Configuration

Global cache

How Bun stores and manages packages in its global cache

All packages downloaded from the registry are stored in a global cache at ~/.bun/install/cache, or the path defined by the environment variable BUN_INSTALL_CACHE_DIR. They are stored in subdirectories named like ${name}@${version}, so multiple versions of a package can be cached.


Minimizing re-downloads

Bun strives to avoid re-downloading packages multiple times. When installing a package, if the cache already contains a version in the range specified by package.json, Bun will use the cached package 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. Bun uses the fastest syscalls available to perform this task. On Linux, it uses hardlinks; on macOS, it uses clonefile.


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 amount of disk space dedicated to node_modules.

This benefit also applies to macOS, but there are exceptions. It uses clonefile which is copy-on-write, meaning it will not occupy disk space, but it will count towards drive's limit. This behavior is useful if something attempts to patch node_modules/*, so it's impossible to affect other installations.