How to safely upgrade Bun and roll back to a previous version
0 reputation · 10 Aug 2020, 15:29 UTC
0 reputation · 10 Aug 2020, 15:29 UTC
When managing a Bun installation in a development or production environment, what are the recommended steps to upgrade to a new stable or canary release while ensuring the ability to verify the update and roll back to a known good version if issues arise? Please outline any verification commands, version‑checking procedures, and rollback strategies that are documented or commonly used with Bun. Include considerations for checking the current version before and after the upgrade, and describe how to revert to the previous Bun binary if the new release causes failures.
35275 reputation · 10 Aug 2020, 16:14 UTC
The safest way to manage Bun versions is through the built-in upgrade command. Because Bun is distributed as a single binary, rolling back is a matter of instructing the runtime to replace itself with a specific previous version.
bun --version
bun upgrade
bun --version
If the new version introduces regressions or failures, you can roll back by specifying the exact version number you recorded in step one.
--version flag to downgrade.
bun upgrade --version 1.0.0
(Replace 1.0.0 with your specific previous version)
bun --version
This approach assumes Bun was installed via the official curl script (typically residing in ~/.bun/bin). If you are using a version manager or a system-level package manager, these commands may not behave as expected.
For production environments where downtime must be minimized, manually backing up the binary is recommended before any upgrade:
cp ~/.bun/bin/bun ~/.bun/bin/bun.bak).upgrade --version command is unavailable, move the backup back into place: mv ~/.bun/bin/bun.bak ~/.bun/bin/bun.Diagnostic Detail: Are you running Bun via the official install script, or are you using a third-party manager like asdf or homebrew? The rollback commands differ for external managers.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 10 Aug 2020, 18:02 UTC
While the bun upgrade command is efficient for stable releases, developers testing experimental features should be aware of the canary channel. To switch to the latest canary build, use:
bun upgrade --canary
For those automating deployments via CI/CD or Docker, relying on the interactive upgrade command can be fragile. A more deterministic approach for version control is using the BUN_VERSION environment variable during the installation phase. By specifying this variable, you can ensure that every environment in your pipeline is pinned to the exact same binary version, eliminating the "it works on my machine" discrepancy that can occur when different team members upgrade at different times.
Verification Tip: After any version change, it is recommended to run bun --version and execute your test suite to ensure that runtime optimizations in the new version haven't introduced regressions in your specific codebase.