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
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@latestYou can use:
bun install
bun add axios
bun run dev
bunx create-next-app@latestThe 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 | bashOn Ubuntu or Debian, install unzip if necessary:
sudo apt install unzipReload your terminal configuration:
source ~/.bashrcWindows
Open PowerShell:
powershell -c "irm bun.sh/install.ps1|iex"Alternatively, install it using Scoop:
scoop install bunInstalling through npm
If you already have Node.js and npm:
npm install -g bunThis is a convenient way to install Bun without using the installation script.
Verify installation
Check whether Bun is installed:
bun --versionTo check the build revision:
bun --revisionIf 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-projectInitialize Bun:
bun initBun generates the initial project files, including:
my-project/
├── index.ts
├── package.json
├── tsconfig.json
├── bun.lock
├── .gitignore
└── README.mdYou can now execute your TypeScript file:
bun run index.tsnpm 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 installWith Bun:
bun installThis 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 axiosWith Bun:
bun add axiosThis adds Axios to your project's dependencies.
Install development dependencies
With npm:
npm install -D typescriptWith Bun:
bun add -d typescriptThe -d flag adds the package under devDependencies.
Install a specific version
bun add axios@1.7.9Install the latest version:
bun add axios@latestInstall an exact version without a version range:
bun add axios@1.7.9 --exactRemove a package
With npm:
npm uninstall axiosWith Bun:
bun remove axiosUpdate packages
Update all dependencies:
bun updateUpdate a specific dependency:
bun update axiosCheck outdated dependencies:
bun outdatedInstall optional dependencies
bun add package-name --optionalInstall peer dependencies
bun add package-name --peerInstall globally
With npm:
npm install -g typescriptWith Bun:
bun add -g typescriptThis 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 lintWith Bun:
bun run dev
bun run build
bun run start
bun run lintYou can also use the shorter syntax:
bun dev
bun build
bun start
bun lintBun can execute package scripts without requiring the run keyword.
Running JavaScript and TypeScript files
With Node.js:
node index.jsWith Bun:
bun run index.jsYou can also execute TypeScript directly:
bun run index.tsFor JSX and TSX:
bun run app.tsxBun handles the required transpilation automatically.
Running commands from node_modules/.bin
Suppose you installed TypeScript:
bun add -d typescriptYou can run the TypeScript compiler:
bunx tsc --noEmitOr execute the local binary directly:
bun run tsc --noEmitScript 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@latestnpx 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@latestWith Bun:
bunx create-next-app@latestAnother example:
bunx cowsay "Hello Bun!"Bun downloads the package when necessary and executes its CLI.
Run a specific package version
bunx create-next-app@15Execute 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-appbunx 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@latestWith Bun:
bun create viteCreate a React project:
bun create vite my-react-app --template reactFor React with TypeScript:
bun create vite my-react-app --template react-tsNavigate into the project:
cd my-react-appInstall dependencies:
bun installStart the development server:
bun run devCreate a Next.js project
With npm:
npx create-next-app@latest my-next-appWith Bun:
bunx create-next-app@latest my-next-appNavigate into the project:
cd my-next-appInstall dependencies if necessary:
bun installStart the development server:
bun run devYour application will be available at:
http://localhost:3000Installing additional packages
For example, install Lucide icons and Zod:
bun add lucide-react zodInstall Tailwind-related development tools if required by your project:
bun add -d prettierYou 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.jsonBun creates:
bun.lockA 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 reactBun updates both:
package.jsonbun.lock
The lockfile should be committed to Git.
Install exact locked dependencies
For CI/CD or production builds:
bun install --frozen-lockfileYou can also use:
bun cibun 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 --versionGet help
bun --helpGet help for a specific command:
bun install --helpExecute a file
bun run index.tsWatch for file changes
bun --watch run server.tsThis restarts the process when files change.
Hot reload
bun --hot run server.tsThis enables Bun's hot-reloading behavior for supported runtime workflows.
Run tests
bun testWatch mode:
bun test --watchBuild an application
bun build ./src/index.ts --outdir ./distClean up dependencies
bun dedupeThis deduplicates compatible dependency versions.
Inspect dependency information
bun pm lsTo understand why a package is installed:
bun pm why reactInspect Bun cache
bun pm cacheRemove the cache:
bun pm cache rmAudit dependencies
bun auditThis 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 installwithout rewriting your application.
Tip 2: Use bunx instead of npx
Whenever you need to execute a package CLI:
bunx create-next-app@latestThis 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 installChoose 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 --noEmitOr install TypeScript as a development dependency and run:
bun run tsc --noEmitTip 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.jsThis 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.tsYou can migrate its package management workflow in a few steps.
Step 1: Install Bun
Follow the installation instructions and verify:
bun --versionStep 2: Navigate to your project
cd my-projectStep 3: Install dependencies
bun installBun reads your existing package.json and installs the declared dependencies.
It also creates:
bun.lockStep 4: Run your existing scripts
For a Next.js application:
bun run devBuild the application:
bun run buildRun the production server:
bun run startStep 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 updateYou 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
- Bun Documentation
- Installation
- Package Manager
- bun install
- bun add
- bunx
- Bun Runtime
- Bun Test
- Bun CLI Reference
All commands and examples are based on Bun's official documentation. Check the documentation for version-specific flags and behavior.
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.