LinuxCommandLibrary

bun

Run, test, build, and manage JavaScript projects

TLDR

Create a new Bun project in the current directory

$ bun init
copy

Run a JavaScript file or a package.json script
$ bun run [path/to/file|script_name]
copy

Run unit tests
$ bun test
copy

Download and install all the packages listed as dependencies in package.json
$ bun [[i|install]]
copy

Add a dependency to package.json
$ bun [[a|add]] [module_name]
copy

Remove a dependency from package.json
$ bun [[rm|remove]] [module_name]
copy

Start a REPL (interactive shell)
$ bun repl
copy

Upgrade Bun to the latest version
$ bun upgrade
copy

SYNOPSIS

bun [subcommand] [options]

PARAMETERS

init
    Initialize a new Bun project with package.json and bun.lockb.

install
    Install dependencies from package.json (20x faster than npm).

add <pkg>
    Add a dependency and install it.

remove <pkg>
    Remove a dependency and update lockfile.

run <script>
    Execute a script from package.json scripts.

bunx <pkg>
    Run a package binary (like npx).

test
    Run tests with Bun's built-in test runner (Jest-compatible).

build
    Bundle or compile code for production.

dev
    Start a development server with hot reloading.

--help
    Show help for bun or a subcommand.

--version
    Print Bun version.

--hot
    Enable hot module reloading (where supported).

DESCRIPTION

Bun is an incredibly fast all-in-one toolkit for JavaScript and TypeScript apps. It serves as a drop-in replacement for Node.js, npm, yarn, esbuild, and Webpack, delivering 3-30x speedups on common tasks like package installation, script execution, bundling, and testing.

Built in Zig using the JavaScriptCore engine (from WebKit), Bun offers native support for TypeScript, JSX, and ESM without configuration. It includes a high-performance bundler, test runner, and dev server. Key features: lightning-fast bun install (often 20x faster than npm), bun run for scripts, bun build for optimized bundles, and full Node.js API compatibility (improving rapidly).

Ideal for modern web development, Bun reduces workflow friction. Install via a simple curl script. While production-ready for many use cases, some niche Node modules may require polyfills due to its youth.

CAVEATS

Bun is rapidly evolving; some Node.js APIs or native modules may lack full compatibility. Use bun --bun for stricter Bun runtime. Not a full Node replacement yet for all edge cases.

INSTALLATION

Unix/macOS: curl -fsSL https://bun.sh/install | bash
macOS: brew install oven-sh/bun/bun
Verifies with bun --version.

KEY SPEED CLAIMS

bun install: 20-30x faster than npm/yarn.
bun run: 4x faster than Node.
bun build: 30-100x faster than Webpack.

HISTORY

Developed by Jarred Sumner (ex-Cloudflare), announced February 2022. Reached v1.0 in March 2024 after 2+ years of open-source development on GitHub. Focuses on speed via Zig and JavaScriptCore; now used in production by Vercel, Replit, and others.

SEE ALSO

node(1), npm(1), yarn(1), deno(1), esbuild(1)

Copied to clipboard