← All articles

Web Development · 3 November 2026 · 12 min read

Bun CLI Cheat Sheet: npm Commands, Installation, and Complete Usage Guide

Learn how to use Bun as an npm alternative. Explore installation, package management, npm command equivalents, running scripts, bunx, project setup, and migrating existing Node.js projects to Bun.

  • Bun
  • npm
  • JavaScript
  • Node.js
  • TypeScript
  • Next.js
  • React
  • Developer Tools
Bun CLI Cheat Sheet: npm Commands, Installation, and Complete Usage Guide

Bun CLI Cheat Sheet: npm Commands, Installation, and Complete Usage Guide

If you have worked with JavaScript or Node.js, chances are you have used npm for installing packages, managing dependencies, and running development scripts.

But there is another tool worth knowing about: Bun.

Bun is a modern JavaScript toolkit that provides a package manager, runtime, test runner, and bundler. One of its biggest advantages is that you can use it as a replacement for npm in existing JavaScript projects without completely changing your development workflow.

For example, instead of writing:

npm install
npm install axios
npm run dev
npx create-next-app@latest

You can use:

bun install
bun add axios
bun run dev
bunx create-next-app@latest

The commands are straightforward, and if you already know npm, learning Bun is relatively easy.

In this guide, we'll focus on using Bun from the terminal, understanding its npm equivalents, and learning the commands you'll actually use in everyday development.

1. What is Bun?

Bun is an all-in-one JavaScript and TypeScript toolkit.

It provides four major capabilities:

  • Package Manager: Installs, removes, and manages dependencies.
  • Runtime: Executes JavaScript and TypeScript files.
  • Test Runner: Runs application tests.
  • Bundler: Bundles JavaScript, TypeScript, and JSX applications.

For developers familiar with npm, the package manager is the most interesting place to start.

You can use Bun in an existing Node.js project that already has a package.json file.

You don't need to rewrite your React, Next.js, or Express application to start using it.

2. Installing Bun

Before using Bun, you need to install its CLI.

Linux and macOS

Open your terminal:

curl -fsSL https://bun.com/install | bash

On Ubuntu or Debian, install unzip if necessary:

sudo apt install unzip

Reload your terminal configuration:

source ~/.bashrc

Windows

Open PowerShell:

powershell -c "irm bun.sh/install.ps1|iex"

Alternatively, install it using Scoop:

scoop install bun

Installing through npm

If you already have Node.js and npm:

npm install -g bun

This is a convenient way to install Bun without using the installation script.

Verify installation

Check whether Bun is installed:

bun --version

To check the build revision:

bun --revision

If both commands work, you're ready to use Bun.

Official installation documentation:

https://bun.com/docs/installation

3. Initialize a Project Using Bun

Just like npm, Bun can initialize a new JavaScript or TypeScript project.

Using bun init

Create a project directory:

mkdir my-project
cd my-project

Initialize Bun:

bun init

Bun generates the initial project files, including:

my-project/
├── index.ts
├── package.json
├── tsconfig.json
├── bun.lock
├── .gitignore
└── README.md

You can now execute your TypeScript file:

bun run index.ts

npm equivalent

npm Bun
npm init bun init
npm init -y bun init -y
npm create vite@latest bun create vite
npx create-next-app@latest bunx create-next-app@latest

4. Installing and Managing Packages

This is where Bun becomes particularly useful.

If you're coming from npm, most of your daily dependency management commands have simple Bun equivalents.

Install all project dependencies

With npm:

npm install

With Bun:

bun install

This reads your package.json and installs the project's dependencies.

It also generates or updates bun.lock.

Install a new package

With npm:

npm install axios

With Bun:

bun add axios

This adds Axios to your project's dependencies.

Install development dependencies

With npm:

npm install -D typescript

With Bun:

bun add -d typescript

The -d flag adds the package under devDependencies.

Install a specific version

bun add axios@1.7.9

Install the latest version:

bun add axios@latest

Install an exact version without a version range:

bun add axios@1.7.9 --exact

Remove a package

With npm:

npm uninstall axios

With Bun:

bun remove axios

Update packages

Update all dependencies:

bun update

Update a specific dependency:

bun update axios

Check outdated dependencies:

bun outdated

Install optional dependencies

bun add package-name --optional

Install peer dependencies

bun add package-name --peer

Install globally

With npm:

npm install -g typescript

With Bun:

bun add -g typescript

This installs the package globally rather than adding it to the current project's dependencies.

Package management command comparison

Operation npm Bun
Install dependencies npm install bun install
Add package npm install pkg bun add pkg
Add dev dependency npm install -D pkg bun add -d pkg
Remove package npm uninstall pkg bun remove pkg
Update packages npm update bun update
Update one package npm update pkg bun update pkg
Check outdated npm outdated bun outdated
Install globally npm install -g pkg bun add -g pkg
Install exact version npm install pkg@1.0.0 bun add pkg@1.0.0

5. Running Scripts: npm run vs bun run

Every JavaScript project generally has a package.json file containing scripts.

For example:

{
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "eslint ."
  }
}

With npm, you execute these scripts using:

npm run dev
npm run build
npm run start
npm run lint

With Bun:

bun run dev
bun run build
bun run start
bun run lint

You can also use the shorter syntax:

bun dev
bun build
bun start
bun lint

Bun can execute package scripts without requiring the run keyword.

Running JavaScript and TypeScript files

With Node.js:

node index.js

With Bun:

bun run index.js

You can also execute TypeScript directly:

bun run index.ts

For JSX and TSX:

bun run app.tsx

Bun handles the required transpilation automatically.

Running commands from node_modules/.bin

Suppose you installed TypeScript:

bun add -d typescript

You can run the TypeScript compiler:

bunx tsc --noEmit

Or execute the local binary directly:

bun run tsc --noEmit

Script execution comparison

npm Bun
npm run dev bun run dev
npm run build bun run build
npm run start bun run start
npm run lint bun run lint
node index.js bun run index.js
npm exec tsc bunx tsc

6. Understanding bunx: The Alternative to npx

If you frequently use npm, you're probably familiar with npx.

For example:

npx create-next-app@latest

npx allows you to execute packages without manually installing them globally.

Bun provides a similar command called bunx.

Basic usage

With npm:

npx create-next-app@latest

With Bun:

bunx create-next-app@latest

Another example:

bunx cowsay "Hello Bun!"

Bun downloads the package when necessary and executes its CLI.

Run a specific package version

bunx create-next-app@15

Execute a package with a different binary name

For packages where the executable name differs from the package name, use -p:

bunx -p @angular/cli ng new my-app

bunx vs npx

npm Bun
npx vite bunx vite
npx eslint . bunx eslint .
npx prettier . bunx prettier .
npx prisma migrate bunx prisma migrate
npx create-vite bunx create-vite
npx create-next-app bunx create-next-app

Tip: Use bunx for executing package CLIs and bun add when you want to add a package permanently to your project.

7. Creating React, Vite, and Next.js Projects with Bun

Bun makes it easy to start new frontend projects.

Here are some common examples.

Create a Vite project

With npm:

npm create vite@latest

With Bun:

bun create vite

Create a React project:

bun create vite my-react-app --template react

For React with TypeScript:

bun create vite my-react-app --template react-ts

Navigate into the project:

cd my-react-app

Install dependencies:

bun install

Start the development server:

bun run dev

Create a Next.js project

With npm:

npx create-next-app@latest my-next-app

With Bun:

bunx create-next-app@latest my-next-app

Navigate into the project:

cd my-next-app

Install dependencies if necessary:

bun install

Start the development server:

bun run dev

Your application will be available at:

http://localhost:3000

Installing additional packages

For example, install Lucide icons and Zod:

bun add lucide-react zod

Install Tailwind-related development tools if required by your project:

bun add -d prettier

You can continue using the same React and Next.js libraries that you would normally install through npm.

8. Lockfiles: package-lock.json vs bun.lock

Whenever you install dependencies, npm and Bun maintain lockfiles.

npm creates:

package-lock.json

Bun creates:

bun.lock

A lockfile stores resolved dependency versions so that different environments can install a consistent dependency tree.

Why is bun.lock important?

Suppose you install React:

bun add react

Bun updates both:

  • package.json
  • bun.lock

The lockfile should be committed to Git.

Install exact locked dependencies

For CI/CD or production builds:

bun install --frozen-lockfile

You can also use:

bun ci

bun ci performs a frozen-lockfile installation.

If your package.json and lockfile disagree, Bun reports an error instead of silently changing the lockfile.

Important migration tip

When migrating an npm project, you can keep your original package-lock.json while testing Bun.

After validating the migration, choose one package manager and keep its corresponding lockfile as the project's source of truth.

Avoid committing multiple competing lockfiles unless your team has a specific reason to maintain them.

9. Other Useful Bun Commands

Apart from package installation and script execution, Bun provides several useful commands for everyday development.

Check Bun version

bun --version

Get help

bun --help

Get help for a specific command:

bun install --help

Execute a file

bun run index.ts

Watch for file changes

bun --watch run server.ts

This restarts the process when files change.

Hot reload

bun --hot run server.ts

This enables Bun's hot-reloading behavior for supported runtime workflows.

Run tests

bun test

Watch mode:

bun test --watch

Build an application

bun build ./src/index.ts --outdir ./dist

Clean up dependencies

bun dedupe

This deduplicates compatible dependency versions.

Inspect dependency information

bun pm ls

To understand why a package is installed:

bun pm why react

Inspect Bun cache

bun pm cache

Remove the cache:

bun pm cache rm

Audit dependencies

bun audit

This checks for known security vulnerabilities in your dependency tree.

Common command reference

Task Command
Check version bun --version
Get help bun --help
Initialize project bun init
Install dependencies bun install
Add dependency bun add pkg
Remove dependency bun remove pkg
Run script bun run dev
Execute CLI bunx pkg
Run TypeScript bun run index.ts
Run tests bun test
Build bundle bun build ./src/index.ts
Watch files bun --watch run index.ts
List packages bun pm ls
Find package usage bun pm why pkg
Update packages bun update
Check outdated packages bun outdated
Audit dependencies bun audit
Clean cache bun pm cache rm

10. Useful Tips When Switching from npm to Bun

Here are some practical things to remember when using Bun in your existing projects.

Tip 1: You don't need to change package.json

Your existing package.json can generally remain unchanged.

Bun understands standard dependency declarations and npm package scripts.

You can start using:

bun install

without rewriting your application.

Tip 2: Use bunx instead of npx

Whenever you need to execute a package CLI:

bunx create-next-app@latest

This is especially convenient when creating projects or running development utilities.

Tip 3: Don't mix package managers unnecessarily

Avoid switching between npm and Bun repeatedly in the same project.

For example, don't routinely run:

npm install
bun install
npm install

Choose one package manager for your project and maintain its lockfile consistently.

Tip 4: Bun doesn't automatically type-check TypeScript

Bun can execute TypeScript directly, but that doesn't mean all TypeScript errors will be caught.

For a full project type check, use:

bunx tsc --noEmit

Or install TypeScript as a development dependency and run:

bun run tsc --noEmit

Tip 5: Check dependency lifecycle scripts

For security reasons, Bun doesn't automatically execute arbitrary dependency lifecycle scripts during installation.

Some packages need installation scripts to download binaries or perform additional setup.

If a trusted dependency needs its lifecycle script, configure it through trustedDependencies in package.json and reinstall.

Tip 6: You can still use Node.js

Using Bun as your package manager doesn't force you to use Bun as your runtime.

For example:

bun install
node server.js

This is perfectly valid.

You can gradually adopt Bun without changing the runtime of an existing application.

11. Migrating an Existing npm Project to Bun

Let's say you already have a Next.js or React application using npm.

Your project might look like this:

my-project/
├── node_modules/
├── src/
├── public/
├── package.json
├── package-lock.json
└── next.config.ts

You can migrate its package management workflow in a few steps.

Step 1: Install Bun

Follow the installation instructions and verify:

bun --version

Step 2: Navigate to your project

cd my-project

Step 3: Install dependencies

bun install

Bun reads your existing package.json and installs the declared dependencies.

It also creates:

bun.lock

Step 4: Run your existing scripts

For a Next.js application:

bun run dev

Build the application:

bun run build

Run the production server:

bun run start

Step 5: Test your application

Check:

  • Development server.
  • Production build.
  • Database connections.
  • API requests.
  • Authentication.
  • External dependencies.

Step 6: Commit the new lockfile

Once everything works, commit bun.lock and remove the old npm lockfile if your team has completed the migration.

You don't need to rewrite your React components, API routes, or application architecture.

12. Final Thoughts

Bun is a practical alternative to npm, especially if you work regularly with JavaScript, React, Next.js, and TypeScript.

The best part is that learning Bun doesn't require learning an entirely new development workflow.

If you already know npm, most of the commands will feel familiar:

# Install dependencies
bun install
 
# Add a package
bun add axios
 
# Add development dependency
bun add -d typescript
 
# Remove a package
bun remove axios
 
# Run development server
bun run dev
 
# Execute a package
bunx create-next-app@latest
 
# Run tests
bun test
 
# Update dependencies
bun update

You can start using Bun today without migrating your entire application to a new runtime.

My recommendation is to start with the package manager, become comfortable with bun install, bun add, bun remove, bun run, and bunx, and then explore its runtime and built-in tools when needed.

You don't have to change how you build applications. You can simply change how you manage and run them.


Official Documentation

All commands and examples are based on Bun's official documentation. Check the documentation for version-specific flags and behavior.

AS

Aditya Manoj Shinde

Author

I'm Aditya, a developer passionate about AI, Machine Learning, and software development. I love exploring new technologies, building projects, and sharing what I learn along the way.