bun add - BunDocumentation Index Search...⌘KInstall Bun Search...Navigation Core Commands bun addRuntimePackage ManagerBundlerTest RunnerGuidesReferenceBlogFeedback:first-child]:!hidden peer-[.is-custom]:[&>:first-child]:sm:!hidden peer-[.is-custom]:[&>:first-child]:md:!hidden peer-[.is-custom]:[&>:first-child]:lg:!hidden peer-[.is-custom]:[&>:first-child]:xl:!hidden">Core Commandsbun installbun addbun removebun updatebunxPublishing & Analysisbun publishbun outdatedbun whybun auditbun infoWorkspace ManagementWorkspacesCatalogsbun linkbun pmAdvanced Configurationbun patchbun --filterGlobal cacheGlobal virtual storeIsolated installsLockfileLifecycle scriptsScopes and registriesOverrides and resolutionsSecurity Scanner API.npmrc support On this page--dev--optional--peer--exact--globalTrusted dependenciesGit dependenciesTarball dependenciesCLI UsageDependency ManagementProject Files & LockfilesInstallation ControlNetwork & RegistryPerformance & ResourceCachingOutput & LoggingGlobal Configuration & ContextHelpCore Commandsbun add Copy pagespan]:line-clamp-1 overflow-hidden group flex items-center py-0.5 gap-1 text-sm text-gray-950/50 dark:text-white/50 group-hover:text-gray-950/70 dark:group-hover:text-white/70 rounded-none rounded-r-xl border px-3 border-gray-200 aspect-square dark:border-white/[0.07] bg-background-light dark:bg-background-dark hover:bg-gray-600/5 dark:hover:bg-gray-200/5" aria-label="More actions" type="button" id="radix-_R_n4ctdbsnlht5lebsnpfdb_" aria-haspopup="menu" aria-expanded="false" data-state="closed"> *]:[overflow-wrap:anywhere]"> Copy pagespan]:line-clamp-1 overflow-hidden group flex items-center py-0.5 gap-1 text-sm text-gray-950/50 dark:text-white/50 group-hover:text-gray-950/70 dark:group-hover:text-white/70 rounded-none rounded-r-xl border px-3 border-gray-200 aspect-square dark:border-white/[0.07] bg-background-light dark:bg-background-dark hover:bg-gray-600/5 dark:hover:bg-gray-200/5" aria-label="More actions" type="button" id="radix-_R_1cctdbsnlht5lebsnpfdb_" aria-haspopup="menu" aria-expanded="false" data-state="closed"> To add a particular package:
terminal Alias — --development, -d, -D
To add a package as a dev dependency ("devDependencies"):
terminal Alias — -E
To add a package and pin to the resolved version, use --exact. This will resolve the version of the package and add it to your package.json with an exact version number instead of a version range.
terminal Note — This would not modify package.json of your current project folder. Alias - bun add --global, bun add -g, bun install --global and bun install -g
To install a package globally, use the -g/--global flag. This will not modify the package.json of your current project. Typically this is used for installing command-line tools.
terminal To install private repositories, your system needs the appropriate SSH credentials to access the repository.
Bun supports a variety of protocols, including github, git, git+ssh, git+https, and many more.
package.json Yes NoSuggest editsRaise issuebun installPreviousbun removeNext⌘I xgithubdiscordyoutubePowered byThis documentation is built and hosted on Mintlify, a developer documentation platform
Fetch the complete documentation index at: /docs/llms.txt
Use this file to discover all available pages before exploring further.
Skip to main contentBun home pageAdd packages to your project with Bun’s fast package manager
bun add preactTo specify a version, version range, or tag: terminal
bun add zod@3.20.0 bun add zod@^3.0.0 bun add zod@latest--dev
bun add --dev @types/react bun add -d @types/react--optional To add a package as an optional dependency ("optionalDependencies"): terminal
bun add --optional lodash--peer To add a package as a peer dependency ("peerDependencies"): terminal
bun add --peer @types/bun--exact
bun add react --exact bun add react -EThis will add the following to your package.json: package.json
{
"dependencies": {
// without --exact
"react": "^18.2.0", // this matches >= 18.2.0
// with --exact
"react": "18.2.0" // this matches only 18.2.0 exactly
}
}
To view a complete list of options for this command:
terminalbun add --help--global
bun add --global cowsay # or `bun add -g cowsay` cowsay "Bun!"
______ ------ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||
Configuring global installation behavior
bunfig.toml[install] # where `bun add --global` installs packages globalDir = "~/.bun/install/global" # where globally-installed package bins are linked globalBinDir = "~/.bun/bin"Trusted dependencies Unlike other npm clients, Bun does not execute arbitrary lifecycle scripts for installed dependencies, such as postinstall. These scripts represent a potential security risk, as they can execute arbitrary code on your machine. To tell Bun to allow lifecycle scripts for a particular package, add the package to trustedDependencies in your package.json. package.json
{
"name": "my-app",
"version": "1.0.0",
"trustedDependencies": ["my-trusted-package"]
}
Bun reads this field and will run lifecycle scripts for my-trusted-package.
Git dependencies
To add a dependency from a public or private git repository:
terminalbun add git@github.com:moment/moment.git
{
"dependencies": {
"dayjs": "git+https://github.com/iamkun/dayjs.git",
"lodash": "git+ssh:http://github.com/lodash/lodash.git#4.17.21",
"moment": "git@github.com:moment/moment.git",
"zod": "github:colinhacks/zod"
}
}
Tarball dependencies
A package name can correspond to a publicly hosted .tgz file. During installation, Bun will download and install the package from the specified tarball URL, rather than from the package registry.
terminalbun add zod@https://registry.npmjs.org/zod/-/zod-3.21.4.tgzThis will add the following line to your package.json: package.json
{
"dependencies": {
"zod": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz"
}
}
CLI Usage
bun add package> @version>Dependency Management --productionbooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Don’t install devDependencies. Alias: -p --omitstringp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Exclude dev, optional, or peer dependencies from install --globalbooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Install globally. Alias: -g --devbooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Add dependency to devDependencies. Alias: -d --optionalbooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Add dependency to optionalDependencies --peerbooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Add dependency to peerDependencies --exactbooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Add the exact version instead of the ^ range. Alias: -E --only-missingbooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Only add dependencies to package.json if they are not already present Project Files & Lockfiles --yarnbooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Write a yarn.lock file (yarn v1). Alias: -y --no-savebooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Don’t update package.json or save a lockfile --savebooleandefault:"true"p:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Save to package.json (true by default) --frozen-lockfilebooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Disallow changes to lockfile --trustbooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Add to trustedDependencies in the project’s package.json and install the package(s) --save-text-lockfilebooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Save a text-based lockfile --lockfile-onlybooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Generate a lockfile without installing dependencies Installation Control --dry-runbooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Don’t install anything --forcebooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Always request the latest versions from the registry & reinstall all dependencies. Alias: -f --no-verifybooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Skip verifying integrity of newly downloaded packages --ignore-scriptsbooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Skip lifecycle scripts in the project’s package.json (dependency scripts are never run) --analyzebooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Recursively analyze & install dependencies of files passed as arguments (using Bun’s bundler). Alias: -a Network & Registry --castringp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Provide a Certificate Authority signing certificate --cafilestringp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Same as —ca, but as a file path to the certificate --registrystringp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Use a specific registry by default, overriding .npmrc, bunfig.toml, and environment variables --network-concurrencynumberdefault:"48"p:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Maximum number of concurrent network requests (default 48) Performance & Resource --backendstringdefault:"clonefile"p:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Platform-specific optimizations for installing dependencies. Possible values: clonefile (default), hardlink, symlink, copyfile --concurrent-scriptsnumberdefault:"5"p:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Maximum number of concurrent jobs for lifecycle scripts (default 5) Caching --cache-dirstringp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Store & load cached data from a specific directory path --no-cachebooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Ignore manifest cache entirely Output & Logging --silentbooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Don’t log anything --verbosebooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Excessively verbose logging --no-progressbooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Disable the progress bar --no-summarybooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Don’t print a summary Global Configuration & Context --configstringp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Specify path to config file (bunfig.toml). Alias: -c --cwdstringp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Set a specific current working directory Help --helpbooleanp:first-child]:mt-0 [&_.prose>p:last-child]:mb-0" data-component-part="field-content">Print this help menu. Alias: -h
Was this page helpful?
bun add - Bun,AI智能索引,全网链接索引,智能导航,网页索引
- Add packages to your project with Bun