Bun Commands

bun commands cheatsheet.

Install, run, test and bundle — the Bun commands you use every day. Tap to copy.

Install & init
bun installInstall all dependencies from package.json
bun add <pkg>Add a package as a dependency
bun add -d <pkg>Add a package as a dev dependency
bun add -g <pkg>Install a package globally
bun remove <pkg>Remove a package
bun initScaffold a new project with a package.json
Run
bun run <script>Run a script defined in package.json
bun <file>.tsRun a TypeScript or JavaScript file directly
bun run startRun the start script
bun --watch <file>Rerun a file on every change
bunx <pkg>Run a package binary without installing it
Test
bun testRun all tests with the built-in test runner
bun test <file>Run tests in a specific file
bun test --watchRerun tests on every change
Bundle & build
bun build ./index.ts --outdir ./outBundle an entrypoint into an output folder
bun build --target bunBundle for the Bun runtime target
Info & maintenance
bun updateUpdate dependencies to the latest allowed versions
bun outdatedShow packages with newer versions available
bun pm lsList installed packages
bun --versionPrint the installed Bun version
bun upgradeUpgrade Bun itself to the latest release

What Bun actually does

Bun is an all-in-one JavaScript toolkit: a fast runtime, a package manager, a test runner and a bundler in a single binary. It reads the same package.json that Node projects already use, so it slots into existing codebases without a rewrite. When you clone a project, a single bun install reads that file and downloads everything into node_modules — usually much faster than the alternatives — and it's the first command you'll run on almost any Bun-based project.

Installing and adding packages

Adding packages has a few flavours worth understanding. bun add <pkg> adds a normal dependency your app needs to run. bun add -d <pkg> marks it as a dev dependency — tools like test runners and bundlers that you need while building but not in production. bun add -g <pkg> installs globally so a command-line tool is available everywhere on your machine, and bun remove <pkg> takes one back out. Getting these distinctions right keeps your project lean and your deployments clean.

Running scripts and files

The scripts section of package.json is where projects define their commands, run with bun run <name>. Bun can also execute source files directly — bun index.ts runs TypeScript with no separate compile step, and bun --watch reruns on every change. The companion command bunx is the one people forget exists and then can't live without — it runs a package's executable without permanently installing it, which is perfect for one-off scaffolding tools or for trying something once.

Testing, bundling and upkeep

Bun ships its own tools, so bun test runs a Jest-style test runner with zero config and bun build bundles an entrypoint into an output folder. A few maintenance habits prevent trouble: bun outdated shows what has newer versions, bun update moves them forward within safe ranges, and bun upgrade keeps Bun itself current. These pair naturally with the Git commands for version control and the Docker commands when you containerise your app.

FAQ

Is Bun a drop-in replacement for npm?
Bun reads the same package.json and runs the same scripts, so bun install and bun run cover most npm workflows; it also bundles a runtime, test runner and bundler that npm doesn't.
How do I run a TypeScript file with Bun?
Just point Bun at the file — bun index.ts runs TypeScript directly with no separate compile step, and bun --watch index.ts reruns it on every change.

More cheatsheets