bun commands cheatsheet.
Install, run, test and bundle — the Bun commands you use every day. Tap to copy.
bun installInstall all dependencies from package.jsonbun add <pkg>Add a package as a dependencybun add -d <pkg>Add a package as a dev dependencybun add -g <pkg>Install a package globallybun remove <pkg>Remove a packagebun initScaffold a new project with a package.jsonbun run <script>Run a script defined in package.jsonbun <file>.tsRun a TypeScript or JavaScript file directlybun run startRun the start scriptbun --watch <file>Rerun a file on every changebunx <pkg>Run a package binary without installing itbun testRun all tests with the built-in test runnerbun test <file>Run tests in a specific filebun test --watchRerun tests on every changebun build ./index.ts --outdir ./outBundle an entrypoint into an output folderbun build --target bunBundle for the Bun runtime targetbun updateUpdate dependencies to the latest allowed versionsbun outdatedShow packages with newer versions availablebun pm lsList installed packagesbun --versionPrint the installed Bun versionbun upgradeUpgrade Bun itself to the latest releaseWhat 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.