How to Install Bun on Ubuntu 26.04 and 24.04

Share

Install Bun on Ubuntu using the official installer, or use npm if you already manage global tools with Node.js. Bun runs JavaScript and TypeScript and includes a package manager, test runner and bundler.

This guide covers installation, a first project, package management, updates, troubleshooting and removal.

Before you begin
  • Ubuntu 26.04 or 24.04, an internet connection and a terminal. The examples use Bash.
  • A supported 64-bit x86 or ARM system. On x86, Bun requires SSE4.2.
  • A normal account. Sudo is needed to install Ubuntu prerequisites, but not for the default Bun installation.
  • Choose one installation method. The npm method requires an existing Node.js and npm installation.

Check your system

Open Terminal and check your Ubuntu version, processor architecture and existing Bun installations:

Copyable code
cat /etc/os-release
uname -m
type -a bun

Look for Ubuntu 26.04 or 24.04 and x86_64 or aarch64. If Bun is not installed, Bash reports that it was not found. If a path appears, note it before installing another copy. On an older x86 computer, look for sse4_2 in the output of lscpu.

Install Bun with the official installer

1. Install the prerequisites

Refresh Ubuntu’s package information and install the download and extraction tools:

Copyable code
sudo apt update && sudo apt install curl unzip ca-certificates

Review the proposed package changes. If APT reports an error, resolve it before continuing.

2. Download and inspect the installer

The official installer runs downloaded code as your user and can update shell startup files. Download it to a temporary file and inspect it first:

Copyable code
bun_installer=$(mktemp) && curl -fsSL https://bun.com/install -o "$bun_installer" && less "$bun_installer"

Press q to close the viewer. Keep this terminal open for the next command. If the download fails or the script is not what you expect, stop. Inspecting a script does not guarantee its safety.

If less is unavailable, install it:

Copyable code
sudo apt install less

Then open the downloaded script in the same terminal and finish inspecting it before running it:

Copyable code
less "$bun_installer"

3. Install Bun

After reviewing the script, run it without sudo:

Copyable code
bash "$bun_installer"

By default, Bun is installed under ~/.bun. Follow the shell instructions printed by the installer. Remove the temporary installer when you are finished:

Copyable code
rm -- "$bun_installer"

4. Verify the installation

Open a new terminal and check the version, revision and command path:

Copyable code
bun --version
bun --revision
command -v bun
bunx --help

A successful version check prints a version number. The path identifies the executable your shell selected. For a default script installation, it normally points to ~/.bun/bin/bun. If the command is not found, see troubleshooting below.

Install Bun with npm

This is an alternative for an existing Node.js and npm environment. Use the account and privilege model you normally use for global npm packages. A user-owned Node version manager normally does not need sudo.

Copyable code
node --version
npm --version
npm install -g bun

If npm reports a permissions error, inspect npm prefix -g and your Node installation before changing permissions. Then check the active Bun and the npm package:

Copyable code
bun --version
type -a bun
npm list -g bun --depth=0

If several paths appear, Bash normally selects the first. Update and remove each installation using the method that installed it.

Create and run a Bun project

Create a new directory and initialize the default project:

Copyable code
mkdir "$HOME/bun-example" && cd "$HOME/bun-example" && bun init -y

If the directory already exists, choose another name. The commands stop if creating or entering the directory fails. Initialization creates project files and may download dependencies.

Run the generated TypeScript file:

Copyable code
bun run index.ts

The starter normally prints Hello via Bun!. Generated files can change with Bun versions. Bun executes TypeScript directly, but running a file does not by itself type-check it.

Try a local HTTP server

In the project directory, create a new file named server.ts using your editor. Choose another name if that file already exists:

Copyable code
const server = Bun.serve({
  hostname: "127.0.0.1",
  port: 3000,
  fetch() {
    return new Response("Hello from Bun!");
  }
});

console.log(`Listening at http://127.0.0.1:${server.port}`);

Start it in the first terminal:

Copyable code
bun run server.ts

In a second terminal, test the response:

Copyable code
curl --noproxy '*' http://127.0.0.1:3000

The response should be Hello from Bun!. The loopback address limits access to the same machine; in an SSH session, that means the remote machine. Press Ctrl+C in the server terminal to stop it. If port 3000 is already in use, change the port in the file and test the new port.

Bun can run TypeScript without type-checking it. To add the compiler separately, see how to install TypeScript on Ubuntu.

Manage packages

Run these examples inside your example project. They change its package manifest, lockfile and installed dependencies:

Copyable code
bun add express
bun add -d prettier
bun remove express

The first command adds a dependency, the second adds a development dependency, and the third removes Express. Use bun install to install a project’s dependencies and bun run <script> to run a package script. Check an existing project’s package manager and lockfile before changing its workflow.

To run a package executable:

Copyable code
bunx prettier --version

bunx can use a local executable or download one into its cache. Running an unfamiliar package executes its code. Some tools require Node.js or Node-specific behavior, so test compatibility before changing an existing workflow.

Inspect and clear the cache

Print the cache location:

Copyable code
bun pm cache

To remove cached downloads:

Copyable code
bun pm cache rm

If you enabled Bun’s optional global store, clearing the cache also removes that shared store. Affected projects need bun install again. Clearing the cache does not remove separate project directories.

Update Bun

For the official installer, use Bun’s self-update command:

Copyable code
bun upgrade
bun --version

For an npm installation, update the global npm package instead, using the same account and privilege model as the original installation:

Copyable code
npm install -g bun@latest
bun --version

APT does not update either of these installations. Bun also supports installing a specific release or trying canary builds. Canary builds are untested and automatically upload crash reports. Check the official installation documentation before using one.

Troubleshoot Bun

Bun: command not found

Open a new terminal. If you used the default installer, test the binary directly:

Copyable code
"$HOME/.bun/bin/bun" --version

If that works, the binary exists but may not be on PATH. If it does not, review the installer output and your BUN_INSTALL setting, if you changed it.

For the current Bash session with the default installation, run:

Copyable code
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
hash -r
bun --version

To make this persistent, add the two export lines to the Bash startup file used by your shell, usually ~/.bashrc, only if they are missing. Start a new terminal and check again. For zsh or fish, follow the installer’s shell-specific instructions. Noninteractive scripts should set PATH explicitly because they may not load interactive shell configuration.

The wrong version runs

List all matching commands and clear Bash’s remembered command paths:

Copyable code
type -a bun
hash -r
command -v bun

PATH order determines which executable runs. Remove or adjust an unwanted installation using its own installation method.

Illegal instruction or unsupported processor

Check the architecture and CPU features:

Copyable code
uname -m
lscpu

Bun supports Linux x64 and ARM64. Current x64 binaries require SSE4.2. An unsupported processor cannot be fixed by changing PATH; check the official requirements for the release you intend to use.

Uninstall Bun

Choose the method you used to install it. Project directories are separate, but the default Bun directory also contains cached files and may contain globally installed tools. Inspect it and back up anything you need first.

Official installer

Inspect the default directory:

Copyable code
ls -la "$HOME/.bun"

The following permanently removes the default directory and everything inside it, including Bun’s cache and user-global tools:

Copyable code
rm -rf -- "$HOME/.bun"

If you set a custom BUN_INSTALL, inspect that location separately and do not assume it is safe to delete. Remove Bun-specific PATH lines from the shell file the installer changed if they are no longer needed. Start a new shell and run type -a bun to check for other installations. Your separate projects and their node_modules remain.

npm

Use the same npm installation and account used to install Bun:

Copyable code
npm uninstall -g bun
hash -r
type -a bun

If Bun still appears, inspect its path: it may be a separate installation.

Frequently asked questions

Does Bun require Node.js?

The official installer does not require Node.js. The npm method requires an existing Node.js and npm setup.

Can Bun run TypeScript?

Yes. Bun can run TypeScript files directly, but running them does not by itself type-check the code.

Does Bun replace Node.js for every project?

No. Compatibility varies. Test your dependencies and scripts before changing an existing workflow.

Will uninstalling Bun delete my projects?

Removing the default Bun directory does not delete separate project directories. It does remove data stored inside that Bun directory, including its cache and user-global tools.

Related Ubuntu guides: Install React on Ubuntu · Install curl on Ubuntu.