LinuxCommandLibrary

bun-remove

Remove Bun project packages

TLDR

Remove a dependency

$ bun remove [package_name]
copy

Remove multiple dependencies
$ bun remove [package_name1 package_name2 ...]
copy

Remove a globally installed package
$ bun remove [[-g|--global]] [package_name]
copy

Remove a dependency without updating the package.json file
$ bun remove --no-save [package_name]
copy

Run the command without actually removing packages (simulate the removal)
$ bun remove --dry-run [package_name]
copy

SYNOPSIS

bun remove [--save-dev] [--save-peer] [--save-optional] [--dry-run] [--confirm] <packages...>
Aliases: bun rm, bun uninstall, bun r

PARAMETERS

--save-dev, -D, --dev
    Remove from devDependencies in package.json

--save-peer, -P, --peer
    Remove from peerDependencies in package.json

--save-optional, -O, --optional
    Remove from optionalDependencies in package.json

--dry-run
    Simulate removal without making changes

--confirm
    Prompt for confirmation before removing packages

DESCRIPTION

The bun remove command is part of the Bun toolkit, a fast all-in-one JavaScript runtime and package manager. It efficiently removes specified packages from your project's node_modules, bun.lockb file, and corresponding sections in package.json (dependencies, devDependencies, etc.).

Bun's removal process is optimized for speed, leveraging its JavaScriptCore-based runtime to perform operations much faster than traditional tools like npm or yarn. It automatically detects the dependency type and updates the lockfile without requiring a full reinstall. This makes it ideal for modern web development workflows.

Usage is straightforward: specify package names, and Bun handles cleanup, including cache invalidation in node_modules/.bun-install-cache. It supports bulk removal and simulates changes with --dry-run for safety. Unlike npm's uninstall, Bun ensures global consistency across installs.

Key benefits include zero-config operation, cross-platform reliability (Linux, macOS, Windows), and integration with Bun's bundler and test runner for seamless development.

CAVEATS

Requires a bun.lockb file; mixing with npm/yarn may cause lockfile conflicts. Does not remove globally installed packages (use bun remove -g).

EXAMPLES

bun remove lodash (removes from dependencies)
bun remove -D jest (removes dev dep)
bun remove --dry-run express react (preview bulk removal)

HISTORY

Introduced in Bun v0.1.0 (September 2022) by Jarred Sumner as part of Bun's drop-in npm/yarn replacement. Evolved rapidly with v1.0+ for better compatibility and performance.

SEE ALSO

npm(1), yarn(1), pnpm(1)

Copied to clipboard