Master Code
On The Go

Learn. Practice. Build.

How-To Guide

How to Install Bun

Bun is a fast, all-in-one JavaScript runtime that combines Node.js, npm, and a bundler in a single tool. Here's how to install it in under 5 minutes.

📋 What You'll Need

✅ Bun is completely free and open source.

🥟 What Is Bun?

Bun is a JavaScript runtime like Node.js, but built for speed. It runs JavaScript and TypeScript directly, includes a package manager, a bundler, a test runner, and a transpiler — all in one binary.

Use it when you want:

1

Open Your Terminal

Windows users: open PowerShell (not Command Prompt). Mac and Linux: open Terminal.

2

Run the Install Command

macOS / Linux:

curl -fsSL https://bun.sh/install | bash

Windows (PowerShell):

powershell -c "irm bun.sh/install.ps1 | iex"

Or via npm (works on any OS if you already have Node.js):

npm install -g bun
3

Verify Installation

Close and reopen your terminal, then run:

bun --version

You should see something like 1.1.30. If you get "command not found", restart your terminal — Bun adds itself to your PATH on install.

4

Test with a Script

Create a file called hello.ts (yes, TypeScript works natively):

const message: string = "Hello from Bun!";
console.log(message);

Run it:

bun run hello.ts

You should see Hello from Bun! — no compilation step needed. 🎉

💡 Bun runs .ts files directly. No tsc compile step, no ts-node. It parses TypeScript on the fly.

🧠 Essential Bun Commands

bun install              # install dependencies (like npm install)
bun add react            # add a package (like npm install react)
bun add -d typescript    # add a dev dependency
bun remove lodash        # remove a package
bun run script.ts        # run a script
bun test                 # run tests
bun build ./index.ts     # bundle for production

If you know npm, you already know Bun — the commands map one-to-one.

⚖️ Bun vs Node.js

🔧 Troubleshooting

"bun: command not found"

Restart your terminal. The installer adds Bun to your PATH, but the current session doesn't pick it up until you reopen.

Windows: install script blocked

Run PowerShell as Administrator, or use the npm fallback: npm install -g bun.

Package doesn't work with Bun

Bun supports most Node packages, but a few use Node-specific APIs. If a package fails, fall back to Node.js for that project.

🎯 What's Next?

← All How-To Guides