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.
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
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:
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:
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.
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.