Behavior
bun link has two modes:
Register a package (no arguments)
Runbun link in a package directory to register it globally:
Use a linked package
Runbun link <package> in another project to use the globally-linked package:
node_modules pointing to the globally-linked package.
Global link directory
Globally-linked packages are stored in:- macOS/Linux:
~/.bun/install/global/node_modules - Windows:
%USERPROFILE%\.bun\install\global\node_modules
Examples
Link a local package globally
Use a linked package in another project
my-app can import from my-utils:
my-utils are immediately reflected in my-app (no rebuild needed).
Link multiple packages
Link in package.json
You can also uselink: protocol directly in package.json:
Link with relative path
Alternatively, use relative paths withfile: protocol:
Binaries
If a linked package has abin field, the binary is linked to the global bin directory:
bun link, the my-cli command is available globally:
Flags
--cwd <path>
Run command in specified directory.
--global-dir <path>
Use a custom global directory.
Unlinking packages
To remove a global link:Comparison with npm link
bun link works similarly to npm link but with some differences:
| Feature | Bun | npm |
|---|---|---|
| Speed | Instant | Slower |
| Global directory | ~/.bun/install/global | {prefix}/lib/node_modules |
| Symlink behavior | Native implementation | Shell symlinks |
| Workspace support | Yes | Yes |
Common issues
Package not found
Ifbun link <package> fails with “not found”, ensure the package is registered:
Changes not reflected
If changes in the linked package aren’t reflected:- Ensure you’re using a symlink (check
node_modules/package) - Restart your development server
- For TypeScript, rebuild the linked package
Use cases
Local development
Develop a library and application simultaneously:Monorepos
For monorepos, consider using workspaces instead ofbun link.