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.
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.
| Step | Command | Watch for |
|---|---|---|
| Install | bun --version | The current shell must see the official binary |
| Script | bun hello.ts | Runs .js / .ts directly; no compile step first |
| Dependency | bun add zod | Use the npm registry name; the lockfile updates |
| Project | bun init | package.json should appear |
Install, run a script, add a package, start a project
- 01Install and confirm the version
Follow bun.sh/docs/installation for the script or Homebrew.
bun --versionshould print a version. If the command is missing, open a new terminal and check PATH. Upgrade withbun upgrade. - 02Run a script
Write
hello.ts(orhello.js) and runbun hello.ts. bun includes a runtime, so TypeScript does not need tsc first. For a package.json script, usebun run <script>. - 03Add one package
In the project directory run
bun add zodas 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. - 04Start a first project
In an empty folder run
bun initand accept the prompts forpackage.jsonand an entry file. Thenbun runthe default script, orbun 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.