How to install and use bun: install, run a script, add a package

Install bun from the official steps, run a script, add one package, and start a first project with bun init.

To run JavaScript or TypeScript locally with bun, finish four jobs: install from the official channel, run a script with bun, bun add one package, then bun init for a first project.

Follow bun.sh/docs/installation instead of guessing package names. The queries are how to install bun, bun add, and bun init. The installer lives at bun.sh.

bunOven command name
addWrites package.json
initScaffolds the first project

Install the official binary for your OS

macOS and Linux

Official script: curl -fsSL https://bun.sh/install | bash. Or brew install oven-sh/bun/bun. Open a new terminal and run bun --version.

Windows

PowerShell: powershell -c "irm bun.sh/install.ps1 | iex". Start a new session and confirm bun is on PATH.

StepCommandWatch for
Installbun --versionThe current shell must see the official binary
Scriptbun hello.tsRuns .js / .ts directly; no compile step first
Dependencybun add zodUse the npm registry name; the lockfile updates
Projectbun initpackage.json should appear

Install, run a script, add a package, start a project

  1. 01
    Install and confirm the version

    Follow bun.sh/docs/installation for the script or Homebrew. bun --version should print a version. If the command is missing, open a new terminal and check PATH. Upgrade with bun upgrade.

  2. 02
    Run a script

    Write hello.ts (or hello.js) and run bun hello.ts. bun includes a runtime, so TypeScript does not need tsc first. For a package.json script, use bun run <script>.

  3. 03
    Add one package

    In the project directory run bun add zod as an example. bun resolves deps and writes the lockfile. On failure, check the package name and the network; do not hand-edit a half-written lockfile.

  4. 04
    Start a first project

    In an empty folder run bun init and accept the prompts for package.json and an entry file. Then bun run the default script, or bun index.ts. For an existing repo, bun install.

curl -fsSL https://bun.sh/install | bash
bun --version
printf 'console.log("ok")\n' > hello.ts
bun hello.ts
mkdir myproject && cd myproject
bun init
bun add zod
# After you write the entry file:
bun index.ts
Is the official install script required?
No. The docs also list Homebrew, npm, Scoop, and other channels. Pick one and verify with bun --version. Do not stack several copies that fight over PATH.
Do I need Node first to run TypeScript?
Not for daily use. bun ships a runtime and can execute .ts directly. If a project script hard-codes node, check the official compatibility notes.
How is bun add different from npm install?
Both add a dependency. bun add uses bun’s resolver and lockfile (bun.lock). Do not alternate npm / pnpm / bun lockfiles in the same directory.
Does install replace a shared diagram?
No. This is a local JavaScript toolchain. When the meeting is the same diagram, open sitdraw.

Get bun on PATH first

Until bun --version works, do not treat a failed init as a template bug. Most failures are a shell that never loaded the PATH the installer changed.

Start the picture