bun by bun.sh

How to Install Bun for global Ubuntu users, other than root

In the modern web development landscape, efficiency and performance are key. That’s where Bun (bun or bun.sh) comes in — a cutting-edge JavaScript runtime that’s been garnering attention for its speed and ease of use.

If you’re considering making the switch to Bun for your server applications, it’s important to understand the installation process, which requires root access due to the level of system integration it necessitates.

My journey with Bun began out of frustration with Node.js, specifically the convoluted process of upgrading Node versions for each user on my Ubuntu cloud server. The promise of Bun’s superior performance was a beacon of hope. But the switch wasn’t without its hurdles.

Installation

Bun’s installation starts innocuously with a simple bash command. Yet, this command places the Bun binary in the /root/ directory by default:

curl -fsSL https://bun.sh/install | bash

While this is standard for applications requiring root privileges, it creates a bottleneck for non-root users who need access to Bun.

To address this, after the script completes its execution, the binary, now located in /root/.bun/bin/, must be moved to a directory included in the system’s PATH, such as /usr/local/bin/:

sudo mv /root/.bun/bin/bun /usr/local/bin/

This change makes the binary globally accessible. However, we must not forget to adjust the binary’s permissions, ensuring that all users have execute rights:

sudo chmod a+x /usr/local/bin/bun

With permissions set, the installation is practically complete. A quick check of Bun’s version should confirm a successful installation:

bun --version
1.0.8

But the true test of accessibility comes when switching to a non-root user. As an example, using the runcloud user, one should be able to run Bun commands seamlessly:

su runcloud
bun --version
1.0.8

Seeing 1.0.8 confirms that Bun is not only installed but also accessible across the system, regardless of privileges. This cross-user functionality is critical in multi-user environments and for maintaining consistent development environments across various setups.

Summary

To sum up, while Bun’s installation requires an initial root access, with a series of simple yet crucial commands, the runtime can be made universally accessible. This effectively democratises the development environment on your server, removing barriers and streamlining the workflow.

With Bun, developers can say goodbye to the cumbersome upgrades and welcome a runtime that’s not only performant but also harmonious with the diverse needs of server users.

Thank you for joining me on this walkthrough, and may your development endeavours be ever more productive with Bun in your toolkit.

bun website: bun.sh