Skip to main content

Adding packages

Use bun add to add a package to your project. The package is installed and saved to package.json.
To add a specific version, version range, or dist-tag:

Dev dependencies

Use -d (or --dev, -D, --development) to save to devDependencies:

Optional dependencies

Use --optional to save to optionalDependencies:

Peer dependencies

Use --peer to save to peerDependencies:

Exact versions

Use --exact (or -E) to pin to the resolved version rather than a range:
This writes the resolved version without a caret:
Without --exact, Bun writes a caret range (^18.2.0), which allows compatible updates.

Global packages

Use -g (or --global) to install a package globally without modifying the current project’s package.json. This is typically used for CLI tools.
Configure the global installation directory in bunfig.toml:

Git dependencies

Add a dependency from a public or private Git repository:
To install a private repository, your system needs the appropriate SSH credentials configured.
Bun supports multiple Git protocols:

Tarball dependencies

Add a package from a hosted .tgz file:
This saves the tarball URL as the version in package.json:

Trusted dependencies

Bun does not run lifecycle scripts for installed dependencies by default. To allow scripts for a specific package, add it to trustedDependencies in package.json:
See Lifecycle Scripts for more details on Bun’s security model.

Removing packages

Use bun remove to uninstall a package and remove it from package.json:
Multiple packages can be removed at once:
bun remove updates the lockfile and removes the package from node_modules.