Utiliser Bun : installation, bun init, bun add, scripts vs npm

Installation officielle, init/add/run jusqu’au premier script dev, équivalence npm.

La première heure avec Bun bloque surtout sur bun init, bun add, bun run et l’équivalent npm / Node.

The query is installer Bun et bun init, bun add, scripts vs npm. This page follows bun.sh/docs for installation, projects, and the CLI. Bun is its own runtime and toolchain; trust bun --version and the live docs. For Python, see our uv vs pip/venv guide; for an earlier Bun intro, Bun install and TypeScript. To walk script output on a call, open wbroom; see create and join a room.

Install Buninit / addbun run scripts

What Bun does in a repo

Bun (Oven) ships a JavaScript/TypeScript runtime, a package manager (npm/yarn/pnpm-like), and bundler/test tooling. Day to day you use bun init for package.json, bun add to install deps into the lockfile, bun run <script> for npm-style scripts, and bun run file.ts to execute sources without a separate compile step in many cases.

init
Scaffold
add
Dependencies
run
Scripts / files

Install Bun

  1. 1

    macOS / Linux script

    Run the documented install command (often curl -fsSL https://bun.sh/install | bash—confirm at bun.sh/docs/installation). Restart the shell or source the profile snippet the installer prints.

  2. 2

    Verify

    bun --version and which bun should point at the official install. On Windows, follow PowerShell/WSL instructions on bun.sh.

  3. 3

    Alongside mise / nvm

    If you use mise for Node, document whether this repo standardizes on Bun or Node so CI matches laptops.

bun init

  1. 1

    Empty folder

    bun init in the target directory; pick a template (blank, React, etc.—CLI options vary). You get package.json and often tsconfig.json.

  2. 2

    Existing npm repo

    With package.json already present, skip init and run bun install (Bun maintains bun.lock per docs).

  3. 3

    First script

    Add "dev": "bun run src/index.ts" (or your framework default) so bun run dev proves the toolchain.

bun add

  1. 1

    Production deps

    bun add lodash mirrors npm install lodash, updating dependencies and the lockfile. Dev deps: bun add -d typescript (flags per docs).

  2. 2

    Clone then install

    After git clone, bun install; in CI use frozen lock installs as documented.

  3. 3

    Don’t dual-lock blindly

    Pick npm or Bun lock strategy; when migrating from npm, follow bun.sh guidance for package-lock.json vs bun.lock.

bun run

  1. 1

    package.json scripts

    bun run dev equals npm run dev. Some builtins omit run (e.g. bun test)—check bun --help.

  2. 2

    Run TypeScript directly

    bun run src/index.ts (or forms in docs) often runs TS without a separate tsc step; production may still use bun build or framework bundlers.

  3. 3

    Env and args

    Pass env vars like npm (PORT=3000 bun run dev) or use .env per Bun’s loading rules.

# First hour · Bun · 2026-10-20
curl -fsSL https://bun.sh/install | bash   # confirm on bun.sh/docs
bun --version
mkdir my-app && cd my-app && bun init
bun add -d typescript
# package.json → "dev": "bun run src/index.ts"
bun run dev

Bun vs npm / Node

Goalnpm / NodeBun
Global CLInpm i -g pkgbun add -g pkg (see docs)
Add depnpm install pkgbun add pkg
Install treenpm ci / npm installbun install
Run scriptnpm run devbun run dev
Run TS fileoften ts-node / tsc firstoften direct bun run file.ts
01

Command not found

Reload shell; ensure ~/.bun/bin is on PATH; remove broken old installs.

02

Install failures

Some native modules need a specific Bun/Node version—run those paths on Node LTS if required.

03

CI drift

Commit bun.lock, pin Bun in CI, document bun install in README.

Suggested path: official install → bun init or bun install → bun add → bun run dev. Trust bun.sh/docs and your local bun --help.

Vs our other Bun post
Earlier post focuses install + TypeScript; this one stresses init / add / run scripts vs npm.
Vs uv
uv is Python; Bun is JS/TS—see uv guide.
Not a wbroom feature guide
Bun CLI only; meetings on wbroom.

Questions à vérifier

Can Bun fully replace Node?

Many apps yes; some native addons or frameworks still require Node LTS—validate with your test suite and bun.sh compatibility notes.

Must I delete package-lock.json?

Standardize on one lockfile strategy; follow bun.sh migration docs instead of letting npm and Bun fight over locks.

bun add vs bun install?

bun add adds/upgrades named packages in the manifest; bun install installs the full tree from manifest + lock.

Do I need tests in hour one?

No—get bun run dev green first; add bun test when the template or team expects it.

Démarrer une réunion