Files
bun.sh/docs/installation.md
cyfung1031 44dd744f0a docs: rearranged cli/runtime related sections (#6275)
* docs: rearranged cli/runtime related sections

* docs: update README.md for the updated docs path

* Updates

* Rearrange

* Rearrange

* Add files

* readme

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
2023-10-10 16:34:35 -07:00

5.0 KiB

Bun ships as a single executable that can be installed a few different ways.

macOS and Linux

{% callout %} Linux users — The unzip package is required to install Bun. Use sudo apt install unzip to install unzip package. Kernel version 5.6 or higher is strongly recommended, but the minimum is 5.1. Use uname -r to check Kernel version. {% /callout %}

{% codetabs %}

$ curl -fsSL https://bun.sh/install | bash # for macOS, Linux, and WSL
# to install a specific version
$ curl -fsSL https://bun.sh/install | bash -s "bun-v1.0.0"
$ npm install -g bun # the last `npm` command you'll ever need
$ brew tap oven-sh/bun # for macOS and Linux
$ brew install bun
$ docker pull oven/bun
$ docker run --rm --init --ulimit memlock=-1:-1 oven/bun
$ proto install bun

{% /codetabs %}

Windows

Bun provides a limited, experimental native build for Windows. At the moment, only the Bun runtime is supported.

  • bun <file>
  • bun run <file>

The test runner, package manager, and bundler are still under development. The following commands have been disabled.

  • bun test
  • bun install/add/remove
  • bun link/unlink
  • bun build

Docker

Bun provides a Docker image that supports both Linux x64 and arm64.

$ docker pull oven/bun
$ docker run --rm --init --ulimit memlock=-1:-1 oven/bun

There are also image variants for different operating systems.

$ docker pull oven/bun:debian
$ docker pull oven/bun:slim
$ docker pull oven/bun:alpine
$ docker pull oven/bun:distroless

Checking installation

To check that Bun was installed successfully, run bun --version.

$ bun --version
1.x.y

To see the precise commit of oven-sh/bun that you're using, run bun --revision.

$ bun --revision
1.x.y+b7982ac1318937560f38e0f8eb18f45eaa43480f

{% details summary="Troubleshoot: command not found" %} Note — If you've installed Bun but are seeing a command not found error, you may have to manually add the installation directory to your PATH. In order for this change to persist across restarts, you'll need to update the configuration file for your system's shell.

To detect your current shell:

$ echo $SHELL
/bin/zsh # or /bin/bash or /bin/fish

Then add these lines to the appropriate file, save it, and open a new shell.

{% codetabs %}

# ~/.bashrc
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
# ~/.zshrc
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
# ~/.config/fish/config.fish
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"

{% /codetabs %}

{% /details %}

Upgrading

Once installed, the binary can upgrade itself.

$ bun upgrade

{% callout %} Homebrew users — To avoid conflicts with Homebrew, use brew upgrade bun instead.

proto users - Use proto install bun --pin instead. {% /callout %}

Bun automatically releases an (untested) canary build on every commit to main. To upgrade to the latest canary build:

$ bun upgrade --canary

View canary build

{% callout %} Note — To switch back to a stable release from canary, run bun upgrade again with no flags. {% /callout %}

Uninstall

If you need to remove Bun from your system, use the following commands.

{% codetabs %}

$ rm -rf ~/.bun # for macOS, Linux, and WSL
$ npm uninstall -g bun
$ brew uninstall bun
$ proto uninstall bun

{% /codetabs %}