Bun is an all-in-one JavaScript toolkit: a fast runtime compatible with most Node.js APIs, a package manager (bun install), a bundler and a test runner. It starts quickly and installs packages much faster than npm, which makes it attractive for both development and lightweight services.
Install
curl -fsSL https://bun.sh/install | bash
source ~/.bashrc
bun --version
The script installs Bun into ~/.bun/bin for your user and adds it to PATH. Bun needs unzip (sudo apt install -y unzip) and a reasonably recent kernel and glibc. A CPU with AVX2 is used by default; Bun publishes “baseline” builds for older CPUs.
Upgrade later with:
bun upgrade
Use it as a package manager
In any Node.js project:
bun install # reads package.json, writes bun.lock
bun add express
bun remove express
bun run build # runs package.json scripts
You can use bun install for speed even if the app itself runs on Node.js.
A minimal Bun HTTP server
// server.ts
const server = Bun.serve({
hostname: "127.0.0.1",
port: Number(process.env.PORT ?? 3000),
fetch(req) {
const url = new URL(req.url);
if (url.pathname === "/health") return new Response("ok");
return new Response("Hello from Bun");
},
});
console.log(`Listening on ${server.url}`);
bun run server.ts
TypeScript runs directly — no build step needed. Many Express/Hono/Elysia apps run on Bun as well.
Run it with systemd
For a server, install Bun for a dedicated user (or copy the binary to /usr/local/bin/bun, which is a single file):
sudo cp ~/.bun/bin/bun /usr/local/bin/bun
sudo useradd --system --create-home --home-dir /srv/bunapp --shell /usr/sbin/nologin bunapp
/etc/systemd/system/bunapp.service:
[Unit]
Description=Bun app
After=network.target
[Service]
User=bunapp
WorkingDirectory=/srv/bunapp/app
Environment=NODE_ENV=production PORT=3000
ExecStart=/usr/local/bin/bun run server.ts
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now bunapp
curl http://127.0.0.1:3000/health
Update the /usr/local/bin/bun copy when you upgrade Bun. PM2 can also run Bun apps (pm2 start server.ts --interpreter bun).
Nginx in front
server {
server_name app.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Then sudo certbot --nginx -d app.example.com.
Compile to a single executable
bun build ./server.ts --compile --outfile myapp
./myapp
The output bundles your code and the Bun runtime into one binary — deploy it like a Go program, without installing Bun on the server.
Docker
The official oven/bun image works well:
FROM oven/bun:1 AS build
WORKDIR /app
COPY package.json bun.lock ./
RUN bun install --frozen-lockfile --production
COPY . .
USER bun
EXPOSE 3000
CMD ["bun", "run", "server.ts"]
Caveats
- Node compatibility is high but not complete. Most npm packages work; some native addons or rarely used Node APIs may not. Test your dependencies.
- Production maturity — Bun is younger than Node.js. For critical services, run your test suite on Bun and monitor closely after switching.
- Lockfile —
bun.lock(text format in recent versions) should be committed.
Bun vs Node.js vs Deno
- Node.js — the most mature ecosystem and tooling.
- Bun — fastest installs and startup, built-in tooling, high Node compatibility.
- Deno — secure-by-default permissions, built-in TypeScript and tools, npm compatibility.
See also npm vs Yarn vs pnpm.