bun-add
Add dependencies to a Bun project
TLDR
Install a single package
Install multiple packages
Install from a Git repository
Install a specific version
Install from local file or directory
Add a dev dependency
Add a package globally
SYNOPSIS
bun add [options] <package[@<version>]>...
PARAMETERS
-D, --dev
Add to devDependencies instead of dependencies
-P, --peer
Add to peerDependencies
-O, --optional
Add to optionalDependencies
-E, --exact
Use exact version without ^ or ~ prefix
-g, --global
Install globally to Bun's global store
--production
Skip devDependencies during install
--registry <url>
Use custom npm registry
--lockfile-only
Update lockfile without installing
--dry-run
Simulate without changes
--force
Force install despite warnings
DESCRIPTION
bun add is a core command in Bun, the ultrafast JavaScript runtime, bundler, and package manager designed as a drop-in replacement for Node.js, npm, and Webpack. It adds specified packages to your package.json file and installs them into node_modules, generating or updating the bun.lockb lockfile for reproducible installs.
Key advantages include blazing speed—often 10-20x faster than npm install or yarn add—due to Bun's native Zig implementation and compatibility with npm registry. It supports semver ranges, git URLs, local paths, and workspace packages. By default, it installs to dependencies; use flags for devDependencies, peers, or optionals. Global installs mimic npm's -g behavior, placing packages in Bun's global store.
Unlike traditional tools, bun add leverages Bun's built-in TypeScript and JSX support, ensuring seamless integration in modern JS/TS workflows. It's ideal for monorepos with workspace declarations, automatically linking local packages.
CAVEATS
Requires Bun installed; bun.lockb is binary and not human-readable. Limited compatibility with some npm scripts or native modules needing Node polyfills. Global installs use Bun's store, not npm's.
EXAMPLES
bun add lodash
bun add -D jest @types/node
bun add -g typescript
bun add git+https://github.com/user/repo
WORKSPACES
Supports yarn-style workspaces; declare in package.json workspaces array for hoisted linking.
HISTORY
Introduced in Bun v0.1.0 (September 2022) by Jarred Sumner as part of the initial all-in-one toolkit. Evolved rapidly with Bun 1.0 stable (2023), matching npm feature parity while emphasizing speed via Zig/C++ backend.


