A single binary that replaces Node.js, npm, webpack, and tsc sounds too good to be true, but Bun delivers exactly that. To install Bun on Ubuntu, you run the official install script or use npm if Node.js is already on the system. Either path drops a self-contained runtime into your home directory with no system-level dependencies beyond curl and unzip.
Bun is not packaged in Ubuntu’s APT repositories, so it manages its own updates independently. The install works the same on Ubuntu 26.04, 24.04, and 22.04. Once it is in place, you can scaffold TypeScript projects with bun init, serve HTTP without extra packages, and swap out npm in existing package.json workflows.
Install Bun on Ubuntu
Bun ships as a single precompiled binary. The official install script handles the download and PATH setup, while an npm method is available for existing Node.js environments.
| Method | Channel | Version | Updates | Best For |
|---|---|---|---|---|
| Official Script | bun.com | Latest | bun upgrade | Most users |
| npm | npmjs.com | Latest | sudo npm update -g bun | Existing Node.js setups |
The official script is the better option for most setups. It keeps Bun independent of Node.js and includes built-in self-update support through bun upgrade.
Update Ubuntu Before Installing Bun
Refresh the package index and apply any pending security patches before installing new software.
sudo apt update && sudo apt upgrade
This guide uses
sudofor commands that need root privileges. If your user is not in the sudoers file yet, follow the guide on how to add and manage sudo users on Ubuntu.
Bun requires curl for downloading and unzip for extracting the binary. Both are usually present on desktop installs, but minimal server images may not include them.
sudo apt install curl unzip
Install Bun via the Official Install Script
The official install script from bun.com downloads the latest release, places the binary in ~/.bun/bin/, and appends the necessary PATH entries to ~/.bashrc.
curl -fsSL https://bun.com/install | bash
The -fsSL flags tell the curl command to fail silently on HTTP errors (-f), suppress the progress meter (-sS), and follow any redirects (-L). The script pipes directly to bash, which runs the installer.
After the script finishes, reload your shell configuration so the new PATH takes effect in your current session.
source ~/.bashrc
If you use
zshorfishinstead of bash, the installer writes to~/.zshrcor~/.config/fish/config.fishrespectively. Runsource ~/.zshrcorexec fishto reload.
Install Bun with npm on Ubuntu
If Node.js and npm are already on your system, you can install Bun as a global npm package. This method is convenient when you want to keep Bun alongside an existing Node.js setup. If you need to install Node.js on Ubuntu first, handle that before continuing.
sudo npm install -g bun
The -g flag installs Bun globally so it is available system-wide. The sudo prefix is required because npm’s default global directory (/usr/local/lib/node_modules) is owned by root.
Verify the Bun Installation on Ubuntu
Check which version is installed.
bun --version
1.3.10
For more detail including the build revision, use the --revision flag.
bun --revision
1.3.10+30e609e08
Create a Bun Project on Ubuntu
Bun includes a built-in project scaffolding tool that generates a working TypeScript project in seconds. Unlike Node.js, Bun executes TypeScript natively without a separate compilation step, so the project is ready to run immediately. If you also work with standalone TypeScript tooling, see how to install TypeScript on Ubuntu for the full compiler setup.
Scaffold a New Bun Project with bun init
Create a project directory and initialize it with Bun’s default template.
mkdir ~/bun-test && cd ~/bun-test
bun init -y
The -y flag accepts all defaults without interactive prompts. Bun generates a package.json, tsconfig.json, a .gitignore, and a starter index.ts file, then installs @types/bun and typescript type definitions automatically.
+ .gitignore
+ index.ts
+ tsconfig.json (for editor autocomplete)
+ README.md
To get started, run:
bun run index.ts
bun install v1.3.10 (30e609e0)
Resolving dependencies
Resolved, downloaded and extracted [20]
Saved lockfile
+ @types/bun@1.3.9
+ typescript@5.9.3
5 packages installed [958.00ms]
Run TypeScript with Bun on Ubuntu
Bun runs TypeScript files directly. No transpiler, no build step, no extra configuration. Execute the generated index.ts to confirm everything is working.
bun run index.ts
Hello via Bun!
You can also use bun run with package.json scripts, the same way npm run works. Any script defined in the "scripts" section of package.json works with bun run <script-name>.
Build an HTTP Server with Bun.serve() on Ubuntu
Bun includes a built-in HTTP server API that does not require any external packages. Replace the contents of index.ts with the following to create a basic server.
const server = Bun.serve({
port: 3000,
fetch(req) {
const url = new URL(req.url);
if (url.pathname === "/") return new Response("Hello from Bun!");
return new Response("Not Found", { status: 404 });
},
});
console.log(`Listening on http://localhost:${server.port}`);
Run the server.
bun run index.ts
Listening on http://localhost:3000
In a second terminal, test the response.
curl http://localhost:3000
Hello from Bun!
Press Ctrl+C in the first terminal to stop the server when you are done testing.
Manage Bun Packages on Ubuntu
Bun works as a drop-in replacement for npm, yarn, and pnpm. It reads package.json and node_modules the same way, so existing Node.js projects work without changes.
| Task | Bun Command | npm Equivalent |
|---|---|---|
| Add a dependency | bun add <pkg> | npm install <pkg> |
| Add a dev dependency | bun add -d <pkg> | npm install --save-dev <pkg> |
| Remove a dependency | bun remove <pkg> | npm uninstall <pkg> |
| Install all from package.json | bun install | npm install |
| Run a script | bun run <name> | npm run <name> |
Add and Remove Bun Packages on Ubuntu
Add packages to a project the same way you would with npm. Bun resolves and installs dependencies significantly faster because it uses a global module cache and parallel downloads.
bun add express
For development-only dependencies like linters or test frameworks, use the -d flag.
bun add -d prettier
Remove a package with bun remove.
bun remove express
Upgrade Bun on Ubuntu
Bun manages its own updates independently of APT. A single command downloads and replaces the binary in place.
bun upgrade
Congrats! You're already on the latest version of Bun (which is v1.3.10)
To try pre-release builds, switch to the canary channel.
bun upgrade --canary
Switch back to the stable channel when you are done testing.
bun upgrade --stable
Canary builds may contain bugs. Use them for testing, not production workloads.
To install a specific older version, pass the version tag to the install script.
curl -fsSL https://bun.com/install | bash -s "bun-v1.3.3"
Troubleshoot Bun on Ubuntu
Most Bun installation issues on Ubuntu come down to PATH configuration or missing prerequisites. These are the most common problems and their fixes.
Fix “bun: command not found” on Ubuntu
This error means your shell cannot find the bun binary. The install script adds PATH entries to ~/.bashrc, but those changes only apply to new shell sessions. Reload your configuration or open a new terminal.
source ~/.bashrc
If the error persists, verify the PATH entries exist in your shell configuration file.
grep -n "bun" ~/.bashrc
119:# bun 120:export BUN_INSTALL="$HOME/.bun" 121:export PATH="$BUN_INSTALL/bin:$PATH"
If those lines are missing, add them manually.
echo '' >> ~/.bashrc
echo '# bun' >> ~/.bashrc
echo 'export BUN_INSTALL="$HOME/.bun"' >> ~/.bashrc
echo 'export PATH="$BUN_INSTALL/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Fix Missing Bun Prerequisites (curl or unzip) on Ubuntu
The install script fails immediately if curl or unzip is not installed. This is common on minimal server images or fresh cloud instances.
sudo apt install curl unzip
After installing both packages, re-run the Bun install script.
Check Bun CPU Compatibility on Ubuntu
Bun’s default build requires a CPU with AVX2 support (Intel Haswell or newer, AMD Excavator or newer). If your CPU does not support AVX2, Bun provides a baseline build that only requires SSE4.2.
Check whether your CPU supports AVX2.
grep -o 'avx2' /proc/cpuinfo | head -1
If the command returns avx2, the default install works. If it returns nothing, install the baseline build instead.
curl -fsSL https://bun.com/install | bash -s -- --baseline
Remove Bun from Ubuntu
The removal steps depend on which installation method you used. Script-installed Bun lives in your home directory and does not need root privileges to remove. npm-installed Bun uses Node.js global paths instead.
Remove Script-Installed Bun from Ubuntu
This permanently deletes the Bun binary, its cache, and any globally installed packages. Project-level
node_modulesdirectories are not affected.
Delete the Bun installation directory.
rm -rf ~/.bun
The rm -rf command removes the directory and all its contents recursively (-r) without prompting for confirmation (-f). Open ~/.bashrc in a text editor and remove the three lines the installer added.
nano ~/.bashrc
Locate and delete the following three lines.
# bun
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
Save the file and reload your shell configuration.
source ~/.bashrc
bun --version
bun: command not found
Remove npm-Installed Bun from Ubuntu
If you installed Bun through npm, remove it with the global uninstall command.
sudo npm uninstall -g bun
Verify Bun is no longer in your PATH.
bun --version
bun: command not found
Frequently Asked Questions
Bun is a JavaScript runtime built on Apple’s JavaScriptCore engine, while Node.js uses Google’s V8 engine. Bun bundles a package manager, bundler, test runner, and native TypeScript support into a single binary. Node.js requires separate tools like npm, webpack, and tsc for those tasks.
Yes. Bun reads package.json and node_modules, implements most Node.js APIs, and works as a drop-in replacement for npm, yarn, and pnpm. Some Node.js-specific APIs that rely on V8 internals may not be available.
No. Bun is a standalone runtime that does not depend on Node.js. The only system prerequisites are curl and unzip for the install script. The npm install method is an alternative for users who already have Node.js, but it is not required.
No. Bun is not packaged in Ubuntu’s official APT repositories. Install it using the official install script from bun.com or via npm.
Run bun upgrade. Bun manages its own updates independently of APT and downloads the latest release directly from bun.com. To try pre-release builds, use bun upgrade --canary and switch back with bun upgrade --stable.
Conclusion
Bun is on your system and ready to run TypeScript, serve HTTP requests, and manage packages from a single binary. Upgrades happen through bun upgrade rather than APT, so the runtime stays current on its own. To expand your setup, install Node.js on Ubuntu for projects that still need V8-specific APIs, or set up Docker on Ubuntu to containerize Bun applications.
Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed:
<code>command</code>command<strong>bold</strong><em>italic</em><a href="URL">link</a><blockquote>quote</blockquote>