Skip to main content

Global cache

还没翻译译自英文(bun.com)本页 18 段都还没译

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 Bun can cache multiple versions of a package.

Configuring cache behavior


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.

Installation details


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 and Windows, clonefile on macOS.


Saving disk space

On Linux and Windows, Bun uses hardlinks to "copy" a module into a project's node_modules directory, so the contents of the package only exist in a single location on disk. This greatly reduces 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.

Installation strategies

译文 © 2026 fanyi.dev · 原文 © 2026 the Bun project (LICENSE.md names no copyright holder) (MIT)