Bun은 Zig로 작성된 올인원 JavaScript 런타임 및 툴킷입니다. 패키지 관리자는 바이너리 락파일, 전역 캐시, 심링크 node_modules로 npm보다 최대 23배 빠르게 설치합니다.
설치 및 기본 명령어
Bun은 몇 초 만에 설치되며 npm 명령어의 드롭인 대체제로 작동합니다.
# Install Bun
curl -fsSL https://bun.sh/install | bash
# Verify installation
bun --version # 1.x.x
# Install dependencies (reads package.json)
bun install
# Install a specific package
bun add express
bun add -d typescript @types/node # dev dependency
bun add -g bunx # global install
# Remove a package
bun remove lodash
# Update all packages
bun update
# Run a script from package.json
bun run build
bun run dev
# Execute a TypeScript file directly (no transpile step)
bun run index.ts워크스페이스 (모노레포 지원)
Bun은 모노레포를 위한 npm 스타일 워크스페이스를 지원합니다.
// package.json — monorepo root
{
"name": "my-monorepo",
"workspaces": [
"packages/*",
"apps/*"
],
"scripts": {
"dev": "bun run --filter '*' dev",
"build": "bun run --filter '*' build",
"test": "bun test"
}
}
// Run a script only in specific workspace
bun run --filter @myapp/web dev
// Install a dependency in a specific workspace
bun add react --cwd apps/web
// Link a local workspace package
// (Bun automatically resolves workspace: protocol)바이너리 락파일 (bun.lockb)
Bun은 JSON 대신 바이너리 락파일을 사용합니다.
# bun.lockb is a binary lockfile (much faster to parse than JSON)
# To view lockfile contents in human-readable form:
bun bun.lockb # prints as yarn.lock format
# To regenerate lockfile:
bun install --frozen-lockfile # CI: fails if lockfile is stale
# Migrating from npm/yarn/pnpm:
# Bun reads package-lock.json, yarn.lock, pnpm-lock.yaml
# to preserve existing versions on first install
# .gitignore for Bun:
# node_modules/
# *.lock (optional — commit bun.lockb for reproducible installs)성능 벤치마크
Bun의 패키지 관리자는 네이티브 코드(Zig), 바이너리 락파일, 병렬 다운로드, 전역 캐시로 모든 대안보다 실질적으로 빠릅니다.
# Benchmark: installing react + 1400 packages
# (warm cache, MacBook M2 Pro)
npm install: 28.3s
yarn install: 14.1s
pnpm install: 9.4s
bun install: 1.2s # 23x faster than npm!
# Cold cache (first install, no node_modules)
npm install: 38.7s
bun install: 4.1s # 9x faster
# bun install uses:
# - Symlink-based node_modules (like pnpm)
# - Binary lockfile (bun.lockb) for fast parsing
# - Parallel downloads
# - Global package cache (~/.bun/install/cache)
# - Native code (written in Zig)bunx와 내장 도구
bunx는 캐시된 바이너리를 사용해 다운로드 없이 패키지를 실행합니다.
# bunx — like npx but instant (no download delay)
bunx create-next-app@latest my-app
bunx prettier --write .
bunx eslint src/
# Run TypeScript directly
bun index.ts # works without ts-node or compilation
bun --watch server.ts # auto-restart on file changes
# Bun's built-in test runner (Jest-compatible API)
bun test
bun test --watch
bun test src/utils.test.ts
// Example test file
import { expect, test, describe } from 'bun:test';
describe('math', () => {
test('adds numbers', () => {
expect(1 + 2).toBe(3);
});
test('async operations', async () => {
const result = await fetch('https://api.example.com/data');
expect(result.ok).toBe(true);
});
});스크립트 및 빌드 통합
Bun은 npm/yarn보다 package.json 스크립트를 더 빠르게 실행합니다.
// package.json scripts with Bun
{
"scripts": {
"dev": "bun --watch src/index.ts",
"build": "bun build src/index.ts --outdir dist --target node",
"bundle:web": "bun build src/app.ts --outdir public/js --target browser --minify",
"test": "bun test",
"lint": "bunx eslint src/",
"format": "bunx prettier --write src/"
}
}
// Bun's built-in bundler (replaces esbuild/webpack for simple cases)
// bun build src/index.ts --outdir dist --target node --minify
// Environment variables (Bun auto-loads .env files)
// No need for dotenv package!
console.log(process.env.DATABASE_URL); // works in Bun automaticallyBun vs npm vs pnpm vs Yarn
| Feature | Bun | npm | pnpm | Yarn |
|---|---|---|---|---|
| Install speed (warm) | 1.2s | 28.3s | 9.4s | 14.1s |
| Lockfile format | Binary | JSON | YAML | Custom text |
| node_modules style | Symlinks | Hoisted | Symlinks | Hoisted/PnP |
| Workspace support | Yes | Yes | Yes | Yes |
| Built-in TypeScript | Yes (native) | No | No | No |
| Built-in test runner | Yes (Jest API) | No | No | No |
| .env auto-loading | Yes | No | No | No |
모범 사례
- 재현 가능한 설치를 위해 bun.lockb를 버전 관리에 커밋하세요.
- 개발에는 bun --watch를 사용하세요.
- npm에서 점진적으로 마이그레이션하세요.
- 모노레포에는 Bun 워크스페이스와 Turborepo를 조합하세요.
- Bun은 .env를 자동으로 로드합니다 — dotenv 패키지 불필요.
자주 묻는 질문
2026년 Bun은 프로덕션에서 사용할 수 있나요?
네. Bun 1.0+는 2023년에 안정화되었으며 99%+ Node.js API 커버리지를 가집니다.
Bun은 모든 npm 패키지와 호환되나요?
거의 모두. 네이티브 Node 애드온을 사용하는 패키지는 예외입니다.
Bun을 Next.js와 함께 사용할 수 있나요?
패키지 관리자로는 즉시 — bun install이 작동합니다.
bun.lockb는 package-lock.json과 어떻게 다른가요?
bun.lockb는 마이크로초 단위로 파싱되는 바이너리 형식입니다.
새 프로젝트에 Bun과 pnpm 중 어느 것을 사용해야 하나요?
둘 다 훌륭합니다. Bun은 올인원 접근법, pnpm은 대규모 모노레포에 적합합니다.