Bun on Ubuntu 24.04 on Azure User Guide
Overview
Bun is the fast all-in-one JavaScript runtime, bundler, transpiler, test runner and package manager - a drop-in Node.js alternative built for speed. It runs JavaScript and TypeScript directly, installs npm dependencies, bundles your code and runs your tests, all from a single binary. The cloudimg image installs Bun 1.3.14 system-wide as the bun command for every user, together with a worked example project - a small Bun.serve HTTP server, a dependency and a test suite - so bun install, bun test and bun run all work out of the box. This is a command-line product - there is no web UI. Backed by 24/7 cloudimg support.
What is included:
- Bun 1.3.14 installed system-wide at
/usr/local/bin/bun, on PATH for every user - A worked example project at
/opt/bun/example(an HTTP server, a dependency and a test file) - A per-user writable copy at
~/bun-examplefor every login user - A login banner pointing at the example and the user guide
- Ubuntu 24.04 LTS base with latest security patches at build time
- 24/7 cloudimg support
Prerequisites
An active Azure subscription, an SSH key pair, and a VNet + subnet in the target region. Standard_B2s (2 vCPU / 4 GiB RAM) is plenty for a Bun development box or CI runner. NSG inbound: allow 22/tcp from your management network. The bundled example needs no inbound ports beyond SSH; if you serve an app from Bun and want it reachable externally, open that port in your NSG.
Step 1 - Deploy from the Azure Marketplace
Sign in to the Azure Portal, choose Create a resource, search the Marketplace for Bun by cloudimg, and select Create. On Basics pick your subscription, resource group, region and size; under Administrator account choose SSH public key and paste your key; under Inbound port rules allow SSH (22). Then Review + create -> Create.
Step 2 - Deploy from the Azure CLI
az vm create \
--resource-group <your-rg> \
--name bun \
--image <marketplace-image-urn> \
--size Standard_B2s \
--admin-username azureuser \
--ssh-key-values ~/.ssh/id_ed25519.pub \
--vnet-name <your-vnet> --subnet <your-subnet> \
--public-ip-sku Standard
Step 3 - Connect to your VM
ssh azureuser@<vm-public-ip>
Step 4 - Confirm Bun is installed
bun --version
It reports 1.3.14. Run bun --help to see the full command list (run, test, install, add, build, x and more).
Step 5 - Get your writable copy of the example
Every login user gets their own writable copy of the worked example. bun install writes a node_modules directory and a lockfile, so the project must be user-writable - this copies the read-only reference from /opt/bun/example:
[ -d ~/bun-example ] || cp -r /opt/bun/example ~/bun-example
cd ~/bun-example && ls -la
The example ships with a package.json (declaring one dependency, left-pad), a server.ts (a small Bun.serve HTTP server) and a server.test.ts test file.
Step 6 - Install dependencies
bun install installs the project's dependencies into node_modules and writes a lockfile - notice how fast it is compared with npm install:
cd ~/bun-example && bun install
Bun reports 1 package installed in tens of milliseconds.
Step 7 - Run the tests
bun test is Bun's built-in test runner - no separate test framework to install. It runs the *.test.ts files in the project:
cd ~/bun-example && bun test
Both tests pass with 2 pass / 0 fail.
Step 8 - Run the server and curl it
bun run server.ts starts the bundled Bun.serve HTTP server on port 3000. This fence starts it in the background, waits for it to come up, curls two endpoints, then stops it - so the command returns cleanly:
cd ~/bun-example
setsid bun run server.ts >/tmp/bun-server.log 2>&1 </dev/null &
for i in $(seq 1 20); do curl -fsS "http://localhost:3000/health" >/dev/null 2>&1 && break; sleep 0.5; done
curl -s "http://localhost:3000/?name=ada"
curl -s "http://localhost:3000/health"
pkill -f "bun run server.ts" || true
The first curl prints Hello, ada! Served by Bun. (the name padded via the left-pad dependency) and the health endpoint prints ok.
Step 9 - Run a script directly
Bun runs TypeScript and JavaScript files directly - no transpile step. Create and run a one-liner:
cd ~/bun-example
echo 'console.log("Bun runs TS directly:", 2 ** 10);' > hello.ts
bun run hello.ts
It prints Bun runs TS directly: 1024.
Step 10 - Use Bun as your package manager and bundler
Bun is a drop-in replacement for npm/yarn/pnpm and a fast bundler:
cd ~/bun-example
bun add zod # add a dependency (writes package.json + lockfile)
bun build server.ts --target=bun --outfile=dist.js && ls -la dist.js
bun add resolves and installs in milliseconds; bun build produces a single bundled output file. Use bunx <pkg> to execute a package binary without installing it globally.
Step 11 - Start a new project
To scaffold your own Bun project anywhere on the VM:
mkdir ~/my-app && cd ~/my-app
bun init -y
bun run index.ts
bun init creates a package.json, a tsconfig.json, an entry file and a .gitignore, giving you a ready-to-develop Bun project.
Maintenance
- Reference template: the read-only example lives at
/opt/bun/example; your writable copy is~/bun-example. - Binary location: Bun is installed at
/usr/local/bin/bunand is on PATH for every user. - Upgrades: upgrade Bun in place with
sudo bun upgrade, or pin a version withsudo bun upgrade --to <version>. - Global installs:
bun add -g <pkg>installs into~/.bun(set viaBUN_INSTALL); add~/.bun/binto your PATH to run global binaries. - Security patches: unattended-upgrades remains enabled so the OS continues to receive security updates automatically.
Support
cloudimg provides 24/7 expert support for this image. Contact support@cloudimg.co.uk.
Bun is a trademark of Oven, Inc. cloudimg is not affiliated with or endorsed by Oven, Inc. This image repackages the open-source Bun runtime (MIT licensed) for convenient deployment on Azure.