Skip to content

Bun Installation

This chapter introduces how to install Bun on different operating systems, as well as verification and configuration after installation.

System Requirements

Bun supports the following operating systems:

Operating SystemVersion RequirementsArchitecture
macOS10.14+x64, ARM64 (M1/M2)
Linuxglibc 2.17+x64, ARM64
WindowsWindows 10+x64
WSLUbuntu 20.04+x64, ARM64

macOS / Linux Installation

Open terminal and run the following command:

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

After installation, restart terminal or run:

bash
source ~/.bashrc  # Linux (bash)
source ~/.zshrc   # macOS (zsh)

Method 2: Using Homebrew (macOS)

bash
brew install oven-sh/bun/bun

Method 3: Using npm

If Node.js is already installed:

bash
npm install -g bun

Method 4: Using Proto

bash
proto install bun

Windows Installation

Open PowerShell as administrator:

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

Method 2: Using Scoop

powershell
scoop install bun

Method 3: Using npm

powershell
npm install -g bun

Method 4: Via WSL

Use Linux installation method in WSL:

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

Verifying Installation

After installation, verify Bun is correctly installed:

bash
# View version
bun --version

# Example output
# 1.1.0

# View help
bun --help

Quick Test

Create a test file:

javascript
// test.js
console.log("Hello from Bun!");
console.log("Bun version:", Bun.version);

Run the test:

bash
bun test.js

Output:

Hello from Bun!
Bun version: 1.1.0

Updating Bun

Using Built-in Command

bash
bun upgrade

Updating to Specific Version

bash
bun upgrade --version 1.1.0

Updating to Latest Beta

bash
bun upgrade --canary

Uninstalling Bun

macOS / Linux

bash
# Delete Bun executable
rm -rf ~/.bun

# Remove PATH from shell config
# Edit ~/.bashrc or ~/.zshrc, remove bun-related lines

Windows

powershell
# Delete Bun directory
Remove-Item -Recurse -Force $env:USERPROFILE\.bun

# Remove from environment variables PATH

Uninstall via Package Manager

bash
# Homebrew
brew uninstall bun

# Scoop
scoop uninstall bun

# npm
npm uninstall -g bun

Configuring Environment Variables

Adding to PATH

If the command is not found after installation, manually add PATH:

Linux/macOS (bash):

bash
echo 'export BUN_INSTALL="$HOME/.bun"' >> ~/.bashrc
echo 'export PATH="$BUN_INSTALL/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

macOS (zsh):

bash
echo 'export BUN_INSTALL="$HOME/.bun"' >> ~/.zshrc
echo 'export PATH="$BUN_INSTALL/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Windows PowerShell:

powershell
# Add to user PATH
$env:BUN_INSTALL = "$env:USERPROFILE\.bun"
[Environment]::SetEnvironmentVariable("BUN_INSTALL", $env:BUN_INSTALL, "User")
[Environment]::SetEnvironmentVariable("PATH", "$env:BUN_INSTALL\bin;$env:PATH", "User")

Bun Configuration File

Bun uses bunfig.toml as the configuration file:

toml
# bunfig.toml

# Package manager configuration
[install]
# Registry to use
registry = "https://registry.npmmirror.com"

# Don't save to package.json during install
save = false

# Dev dependency install location
dev = true

# Run configuration
[run]
# Silent mode
silent = false

# Test configuration
[test]
# Test timeout (milliseconds)
timeout = 5000

# Coverage report
coverage = true

Configuration File Location

Bun searches for configuration in the following order:

  1. ./bunfig.toml (current directory)
  2. $XDG_CONFIG_HOME/bun/bunfig.toml
  3. ~/.bunfig.toml

Common Installation Issues

Issue 1: Insufficient Permissions

bash
# Linux/macOS
curl -fsSL https://bun.sh/install | sudo bash

# Or change install directory permissions
sudo chown -R $USER ~/.bun

Issue 2: Network Issues

Use mirror acceleration:

bash
# Use domestic mirror
curl -fsSL https://bun.sh/install | bash -s -- --mirror

Issue 3: Command Not Found

Ensure PATH is configured correctly:

bash
# Check Bun installation location
which bun
# or
echo $BUN_INSTALL

Issue 4: Windows Execution Policy

powershell
# Temporarily allow script execution
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

IDE Support

VS Code

Install Bun extension for better development experience:

  1. Open VS Code extension marketplace
  2. Search for "Bun"
  3. Install the official extension

Other IDEs

  • WebStorm: Native Bun support
  • Vim/Neovim: Use LSP configuration
  • Sublime Text: Install related plugins

Summary

This chapter covered:

  • ✅ Installing Bun on macOS, Linux, Windows
  • ✅ Verifying installation and version management
  • ✅ Configuring environment variables and config files
  • ✅ Solving common installation issues

Next Steps

After installation, continue reading Quick Start to create your first Bun project.

Content is for learning and research only.