Purpose

bun link is a package linking command that registers local packages for development use across projects without publishing to npm. It creates symlinks between packages, enabling rapid iteration when developing interdependent packages.

Basic Syntax

Terminal window
# Register current package as linkable
bun link
# Link a registered package into current project
bun link <package-name>
# Unregister a package
bun unlink

How It Works

Step 1: Register the Package

Navigate to your package directory and run:

Terminal window
cd /path/to/my-package
bun link

Output:

bun link v1.3.3 (7416672e)
Success! Registered "my-package"
To use my-package in a project, run:
bun link my-package
Or add it in dependencies in your package.json file:
"my-package": "link:my-package"

This registers the package in Bun’s global package registry for linking.

In your consuming project:

Terminal window
cd /path/to/consuming-app
bun link my-package

This creates a symlink in node_modules/my-package pointing to your local package directory.

Step 3: Add to package.json (Optional)

Use the --save flag to persist the link in package.json:

Terminal window
bun link my-package --save

This adds a special version specifier:

{
"dependencies": {
"my-package": "link:my-package"
}
}

CLI Options

FlagAliasDescription
--save-sAdd package to package.json with link specifier
--global-gInstall globally
--production-pSkip devDependencies
--force-fReinstall all dependencies

Use Cases

Local Monorepo Development

When developing packages within a monorepo:

Terminal window
# In package A
cd packages/core
bun link
# In package B
cd packages/app
bun link core

Testing Before Publishing

Test package changes in a real project before publishing to npm:

Terminal window
# In your package
bun link
# In test app
bun link your-package
# Make changes to package...
# Test immediately in app without republishing

NestJS Module Development

Develop NestJS modules locally alongside applications:

Terminal window
# In shared NestJS module
cd libs/auth-module
bun link
# In NestJS app
cd apps/api
bun link auth-module
Featurebun linknpm link
SpeedFast (native implementation)Slower
Symlink creationDirect symlink to local dirTwo-step process
Global registryBun-specificnpm global
package.json supportlink: specifierManual setup
Cross-compatibilityBun projects onlyWorks with npm/yarn

Unlinking

Remove a linked package:

Terminal window
# Unregister from global registry
cd /path/to/package
bun unlink
# Or remove link from consuming project
cd /path/to/consuming-app
bun unlink my-package

Common Patterns

Instead of using Bun workspaces, you can manually link packages:

Terminal window
# Setup
cd package-a && bun link
cd ../package-b && bun link package-a
# Teardown
cd package-a && bun unlink

Development Dependency Linking

Link packages needed only for development:

{
"devDependencies": {
"test-utils": "link:test-utils"
}
}

Troubleshooting

If bun link <package> fails:

  1. Verify package is registered: bun link in package directory
  2. Check package name matches package.json name field
  3. Ensure you’re using the correct package name (not file path)

Changes Not Reflected

If changes to linked package aren’t appearing:

  1. Restart your development server (some bundlers cache node_modules)
  2. Clear Bun cache: bun pm cache rm
  3. Re-link: bun unlink <package> && bun link <package>

Deployment Issues

Important: Linked packages won’t work in production. Before deploying:

  1. Publish package to npm
  2. Update package.json to use published version
  3. Run bun install to fetch from npm

Sources

  1. bun link – Package manager | Bun Docs
  2. Bun package manager vs npm, Yarn, and pnpm in 2025