# Install Bun
curl -fsSL https://bun.sh/install | bash
# Reload your shell configuration
source ~/.bashrc
# or if you use zsh:
source ~/.zshrc
# Verify installation
bun --version
On Windows, it’s best to use PowerShell or WSL. Git Bash support is limited
# Option 1: Using PowerShell (recommended, run in PowerShell not Git Bash)
powershell -c "irm bun.sh/install.ps1 | iex"
# Option 2: Using WSL (Windows Subsystem for Linux)
# If you have WSL installed, use the Linux command above
# Verify (in Git Bash or PowerShell)
bun --version
# Initialize a new project (creates package.json)
bun init
# Install all dependencies from package.json
bun install
# or shorter:
bun i
# Add a package
bun add <package> # Production dependency
bun add -d <package> # Dev dependency
bun add -g <package> # Global install
# Examples:
bun add react react-dom
bun add -d typescript @types/react
# Remove a package
bun remove <package>
# Update packages
bun update # Update all
bun update <package> # Update specific package
# List installed packages
bun pm ls
# Run a JavaScript/TypeScript file directly (no compilation needed!)
bun run index.ts
bun run app.js
# Or
bun app.js
bun index.ts
# Execute a script from package.json
bun run dev
bun run build
bun run test
# Or just:
bun dev
# Caution!
# For built-in commands like "build", "test", "add", etc. run is needed
# bun build runs the built-in command not the script named build
# Create a new project with template
bun create <template> <directory>
# Examples:
bun create react my-app
bun create next my-next-app
bun create vite my-vite-app
# Initialize in current directory
bun init
{
"scripts": {
"dev": "bun run index.ts",
"start": "bun run index.ts"
}
}
# Or
{
"scripts": {
"dev": "bun index.ts",
"start": "bun index.ts"
}
}