bun
Run, test, build, and manage JavaScript projects
TLDR
Run a JavaScript file or a package.json script
Run unit tests
Download and install all the packages listed as dependencies in package.json
Add a dependency to package.json
Remove a dependency from package.json
Create a new Bun project in the current directory
Start a REPL (interactive shell)
Upgrade Bun to the latest version
SYNOPSIS
bun [command] [options] [arguments]
Common commands:
bun run [script]
bun install
bun add [package]
bun remove [package]
bun build [entrypoint]
bun test [files]
bun create [template] [project_name]
PARAMETERS
run
Executes scripts defined in package.json or any JavaScript/TypeScript file.
install
Installs project dependencies defined in package.json. Known for extreme speed.
add
Adds one or more packages to the project's dependencies.
remove
Removes one or more packages from the project's dependencies.
build
Bundles and transpiles JavaScript/TypeScript code for deployment.
test
Runs unit and integration tests with built-in test runner.
create
Initializes a new project from a template.
upgrade
Upgrades Bun to the latest version.
DESCRIPTION
Bun is an all-in-one JavaScript runtime designed for speed and efficiency. Developed by Jarred Sumner, it aims to provide a faster alternative to existing JavaScript tools like Node.js and npm. Unlike traditional Linux commands, Bun is primarily a user-space application used for developing and running web applications. It's built with the Zig programming language and uses JavaScriptCore, Apple's JavaScript engine, for execution.
Bun bundles several functionalities that are typically handled by separate tools in the JavaScript ecosystem: it acts as a runtime (like Node.js), a package manager (like npm or Yarn), a bundler (like Webpack or esbuild), and a test runner (like Jest). This integrated approach reduces complexity and startup times, making development workflows faster. On Linux, Bun is installed as a standalone executable and invoked from the terminal to manage JavaScript/TypeScript projects, run server-side applications, or build front-end code.
CAVEATS
Bun is a relatively new and rapidly evolving tool; its API and features may change between versions. It is not a core Linux utility but a third-party runtime primarily for web development, requiring separate installation. While highly compatible with Node.js APIs, some edge cases or native modules might behave differently or require specific workarounds. Its performance benefits are most apparent in I/O-bound tasks and large dependency trees.
INSTALLATION ON LINUX
Bun can be installed on Linux typically via a shell script:
curl -fsSL https://bun.sh/install | bash
or by downloading a pre-built binary. Users often add the Bun executable to their PATH environment variable for easy access from any directory.
curl (1) is often used for downloading the installation script, and bash (1) for executing it.
HISTORY
Bun was publicly launched in July 2022 by Jarred Sumner, with the goal of creating a faster and more integrated JavaScript toolkit. It quickly gained traction in the developer community due to its impressive performance benchmarks and its all-in-one approach. Its development is ongoing, with frequent updates introducing new features and improvements. It represents a significant innovation in the JavaScript runtime landscape.