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.
Check your system
Open Terminal and check your Ubuntu version, processor architecture and existing Bun installations:
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:
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:
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:
Then open the downloaded script in the same terminal and finish inspecting it before running it:
3. Install Bun
After reviewing the script, run it without sudo:
By default, Bun is installed under ~/.bun. Follow the shell instructions printed by the installer. Remove the temporary installer when you are finished:
4. Verify the installation
Open a new terminal and check the version, revision and command path:
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.
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:
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:
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:
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:
Start it in the first terminal:
In a second terminal, test the response:
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:
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:
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:
To remove cached downloads:
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:
For an npm installation, update the global npm package instead, using the same account and privilege model as the original installation:
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:
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:
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:
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:
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:
The following permanently removes the default directory and everything inside it, including Bun’s cache and user-global tools:
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:
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.
