How to Install Bun on macOS, Windows, and Linux

November 2, 2024 (2w ago)

How to Install Bun on macOS, Windows, and Linux

Bun is a modern JavaScript runtime that promises high performance and streamlined tooling for web development. Installing Bun on your system is straightforward, and this guide will walk you through the steps for installing it on macOS, Windows, and Linux. Follow the steps for your operating system, and start building applications with Bun in no time.

Installation Overview

Bun’s installation can be done with a single command across various platforms. Depending on your system, the installation command may differ slightly. Let's explore each operating system in detail.


Installation on macOS

For macOS users, installing Bun is quick and simple using curl:

  1. Open Terminal: Press Command + Space, type "Terminal," and open it.

  2. Run the Installation Command: Paste the following command in the Terminal and press Enter.

    curl -fsSL https://bun.sh/install | bash
  3. Add Bun to Your Path: After installation, ensure Bun is available globally by adding it to your path. This step may be prompted automatically.

    echo 'export PATH="$HOME/.bun/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc
  4. Verify Installation: Check that Bun was installed successfully by running:

    bun --version

You should see Bun’s version number, confirming the installation.


Installation on Windows

For Windows, you can install Bun using the Windows Subsystem for Linux (WSL) or using PowerShell with a curl command.

Method 1: Installing Bun via WSL (Recommended)

  1. Install WSL: If you haven’t already, install WSL with the following PowerShell command (run as Administrator):

    wsl --install

    Restart your computer after WSL is installed, then open Ubuntu or your preferred Linux distribution.

  2. Run the Installation Command: In the WSL Terminal, run:

    curl -fsSL https://bun.sh/install | bash
  3. Add Bun to Your Path:

    echo 'export PATH="$HOME/.bun/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc
  4. Verify Installation:

    bun --version

Method 2: Installing Bun via PowerShell (Direct)

If you don’t want to use WSL, you can try installing directly via PowerShell:

  1. Run PowerShell as Administrator.

  2. Download and Install Bun:

    iwr https://bun.sh/install -useb | iex
  3. Restart PowerShell and verify the installation with:

    bun --version

Installation on Linux

On Linux, you can install Bun with a single curl command.

  1. Open Terminal.

  2. Run the Installation Command:

    curl -fsSL https://bun.sh/install | bash
  3. Add Bun to Your Path: After installation, make sure Bun is added to your system’s PATH by adding this line to .bashrc or .zshrc:

    echo 'export PATH="$HOME/.bun/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc
  4. Verify Installation:

    bun --version

Additional Platforms and Advanced Options

Bun provides additional options for specific package managers, such as Homebrew on macOS, Scoop for Windows, or Snap on Linux. For detailed instructions, refer to the Bun documentation.

Installing Bun with Homebrew (macOS and Linux)

If you use Homebrew, you can install Bun with:

brew tap oven-sh/bun
brew install bun

Installing Bun with Scoop (Windows)

For Windows users who prefer Scoop, use:

scoop install bun

After installation, verify Bun’s availability by running:

bun --version

Summary

Bun is a fast and modern JavaScript runtime that’s easy to install across different platforms:

Each installation method provides a quick way to start using Bun, allowing developers to enjoy its performance and integrated tooling in any environment.