LinuxCommandLibrary

bun-install

Install project dependencies

TLDR

Install all dependencies listed in package.json

$ bun [[i|install]]
copy

Install a single package (this is an alias for bun add)
$ bun [[i|install]] [package_name]@[version]
copy

Install a package globally
$ bun [[i|install]] [[-g|--global]] [package_name]
copy

Install only production dependencies (skips devDependencies)
$ bun [[i|install]] --production
copy

Install dependencies exactly from the bun.lockb lockfile (frozen lockfile)
$ bun [[i|install]] --frozen-lockfile
copy

Force re-download all packages from the registry, ignoring the cache
$ bun [[i|install]] [[-f|--force]]
copy

SYNOPSIS

bun install [<packages...>] [<options>]

PARAMETERS

<packages...>
    Optionally specify one or more packages to install. If no packages are specified, bun install installs all dependencies listed in package.json.

--frozen-lockfile
    Ensures the bun.lockb lockfile is up-to-date with package.json and does not allow any modifications to it. Fails if the lockfile is out of sync or missing.

--production, -P
    Installs only production dependencies, omitting devDependencies.

--dry-run
    Performs all actions without actually writing files to disk, showing what would happen.

--offline
    Installs packages from the local Bun cache only, without attempting network requests.

--no-scripts
    Prevents the execution of preinstall, install, and postinstall lifecycle scripts defined in package.json.

--loglevel <level>
    Sets the verbosity of Bun's output (e.g., info, warn, error, silent).

--global, -g
    Installs the specified package globally on the system, making its executables available in the PATH.

DESCRIPTION

bun install is the command used within the Bun JavaScript runtime to install project dependencies. It functions similarly to `npm install` or `yarn install`, reading the package.json file to determine required packages and their versions.

A core distinguishing feature of bun install is its exceptional speed, often completing installations significantly faster than traditional package managers due to its native implementation, use of system calls, and efficient caching. When executed, it downloads and places packages into the node_modules directory and generates a bun.lockb lockfile to ensure reproducible builds. This command is crucial for setting up a JavaScript or TypeScript project managed by Bun, ensuring all necessary libraries are available for development and execution. It leverages Bun's built-in bundler and runtime capabilities for a cohesive and high-performance development experience.

CAVEATS

Requires the Bun runtime to be installed on the system.
The bun.lockb file format is unique to Bun and is not directly compatible with package-lock.json or yarn.lock. While Bun aims for broad compatibility, some highly customized or older Node.js scripts and packages might exhibit different behaviors or require specific polyfills.
Performance benefits are most noticeable on larger projects with many dependencies or during frequent re-installations.

LOCKFILE

bun install generates and utilizes a binary lockfile named bun.lockb. This file ensures deterministic installs by recording the exact dependency tree and cryptographic hashes of installed packages. Unlike text-based lockfiles (like package-lock.json), bun.lockb is a binary format optimized for Bun's internal operations, contributing to its speed.

CACHING

Bun employs an aggressive caching strategy for downloaded packages. When you run bun install, it first checks its global cache for required packages. If a package is found in the cache, it's used directly, significantly reducing network requests and installation times for subsequent projects or clean installs.

NODE_MODULES

Similar to other Node.js package managers, bun install places project dependencies into a node_modules directory at the root of your project. This directory structure is compatible with the Node.js module resolution algorithm, allowing seamless integration with existing JavaScript and TypeScript projects.

HISTORY

bun install is a foundational command within the Bun JavaScript runtime, first introduced to the public as part of Bun's initial alpha and beta releases. Developed by Jarred Sumner, Bun's primary goal was to offer a significantly faster, all-in-one toolkit for JavaScript development, including a runtime, bundler, and package manager. The install command was designed from the outset to be a high-performance, drop-in replacement for existing package managers like npm and Yarn, aiming to address common developer frustrations with slow dependency installation times. Its stable 1.0 release in September 2023 solidified its position as a robust and speed-optimized option for managing project dependencies.

SEE ALSO

bun(1), bun add(1), bun remove(1), bun update(1), bun run(1), npm install(1), yarn install(1)

Copied to clipboard