Migrate from npm install to bun install
bun install is a fast, Node.js-compatible npm client.
To migrate from npm install to bun install, run bun install instead of npm install.
- Designed for Node.js & Bun:
bun installinstalls a Node.js compatiblenode_modulesfolder. You can use it in place ofnpm installfor Node.js projects without any code changes and without using Bun's runtime. - Automatically converts
package-lock.jsonto Bun'sbun.locklockfile format, preserving your existing resolved dependency versions. You can secretly usebun installin place ofnpm installat work without anyone noticing. .npmrccompatible:bun installreads npm registry configuration from npm's.npmrc, so you can use the same configuration for both npm and Bun.- Hardlinks: On Windows and Linux,
bun installuses hardlinks to save disk space and speed up installs.
# It only takes one command to migrate
bun i
# To add dependencies:
bun i @types/bun
# To add devDependencies:
bun i -d @types/bun
# To remove a dependency:
bun rm @types/bunRun package.json scripts faster#
Run scripts from package.json, executables from node_modules/.bin (like npx), and JavaScript/TypeScript files (like node), all with a single command.
| NPM | Bun |
|---|---|
npm run <script> | bun <script> |
npm exec <bin> | bun <bin> |
node <file> | bun <file> |
npx <package> | bunx <package> |
bun run <executable> uses the locally-installed executable.
# Run a package.json script:
bun my-script
bun run my-script
# Run an executable in node_modules/.bin:
bun my-executable # such as tsc, esbuild, etc.
bun run my-executable
# Run a JavaScript/TypeScript file:
bun ./index.tsWorkspaces? Yes.#
bun install supports workspaces similarly to npm, with more features.
In package.json, set "workspaces" to an array of relative paths.
{
"name": "my-app",
"workspaces": ["packages/*", "apps/*"]
}Filter scripts by workspace name#
In Bun, the --filter flag accepts a glob pattern and runs the command concurrently for every workspace package whose name matches it, respecting dependency order.
bun --filter 'lib-*' my-script
# instead of:
# npm run --workspace lib-foo --workspace lib-bar my-scriptUpdate dependencies#
bun update <package> updates a dependency to the latest version that satisfies the semver range in package.json.
# Update a single dependency
bun update @types/bun
# Update all dependencies
bun update
# Ignore semver, update to the latest version
bun update @types/bun --latest
# Update a dependency to a specific version
bun update @types/bun@1.3.3
# Update all dependencies to the latest versions
bun update --latestView outdated dependencies#
To view outdated dependencies, run bun outdated. It works like npm outdated, with more compact output.
bun outdatedββββββββββββββββββββββββββββββββββββββββββ¬ββββββββββ¬βββββββββ¬βββββββββ
β Package β Current β Update β Latest β
ββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌβββββββββΌβββββββββ€
β @types/bun (dev) β 1.1.6 β 1.1.10 β 1.1.10 β
ββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌβββββββββΌβββββββββ€
β @types/react (dev) β 18.3.3 β 18.3.8 β 18.3.8 β
ββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌβββββββββΌβββββββββ€
β @typescript-eslint/eslint-plugin (dev) β 7.16.1 β 7.18.0 β 8.6.0 β
ββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌβββββββββΌβββββββββ€
β @typescript-eslint/parser (dev) β 7.16.1 β 7.18.0 β 8.6.0 β
ββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌβββββββββΌβββββββββ€
β @vscode/debugadapter (dev) β 1.66.0 β 1.67.0 β 1.67.0 β
ββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌβββββββββΌβββββββββ€
β esbuild (dev) β 0.21.5 β 0.21.5 β 0.24.0 β
ββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌβββββββββΌβββββββββ€
β eslint (dev) β 9.7.0 β 9.11.0 β 9.11.0 β
ββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌβββββββββΌβββββββββ€
β mitata (dev) β 0.1.11 β 0.1.14 β 1.0.2 β
ββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌβββββββββΌβββββββββ€
β prettier-plugin-organize-imports (dev) β 4.0.0 β 4.1.0 β 4.1.0 β
ββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌβββββββββΌβββββββββ€
β source-map-js (dev) β 1.2.0 β 1.2.1 β 1.2.1 β
ββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌβββββββββΌβββββββββ€
β typescript (dev) β 5.5.3 β 5.6.2 β 5.6.2 β
ββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββ΄βββββββββ΄βββββββββList installed packages#
bun pm ls lists the packages installed in the node_modules folder, using Bun's lockfile as the source of truth. Pass the -a flag to also list transitive dependencies.
# List top-level installed packages:
bun pm lsmy-pkg node_modules (781 installed)
βββ @types/node@20.16.5
βββ @types/react@18.3.8
βββ @types/react-dom@18.3.0
βββ eslint@8.57.1
βββ eslint-config-next@14.2.8
...# List all installed packages:
bun pm ls -amy-pkg node_modules
βββ @alloc/quick-lru@5.2.0
βββ @isaacs/cliui@8.0.2
β βββ strip-ansi@7.1.0
β βββ ansi-regex@6.1.0
βββ @jridgewell/gen-mapping@0.3.5
βββ @jridgewell/resolve-uri@3.1.2
...Create a package tarball#
bun pm pack creates a tarball of the package in the current directory.
# Create a tarball
bun pm packTotal files: 46
Shasum: 2ee19b6f0c6b001358449ca0eadead703f326216
Integrity: sha512-ZV0lzWTEkGAMz[...]Gl4f8lA9sl97g==
Unpacked size: 0.41MB
Packed size: 117.50KBShebang#
If the package references node in the #!/usr/bin/env node shebang, bun run respects it by default and uses the system's node executable. To force it to use Bun instead, pass --bun to bun run.
When you pass --bun, Bun creates a symlink to the locally-installed Bun executable named "node" in a temporary directory and adds it to your PATH for the duration of the script.
# Force using Bun's runtime instead of node
bun --bun my-script
# This also works:
bun run --bun my-scriptGlobal installs#
Install packages globally with bun i -g <package>. By default, they go into a .bun/install/global/node_modules folder inside your home directory.
# Install a package globally
bun i -g eslint
# Run a globally-installed package without the `bun run` prefix
eslint --init