Bun bun install vs npm install: Speed and Differences
With the same package.json dependencies, bun install finished faster than npm install. On the first run, with no cache and no lockfile, npm took 14.98 seconds and Bun took 3.64 seconds (median of 3 runs). However, the results are not exactly the same. Before you switch, you need to know that the lockfile changes to bun.lock, and that Bun only runs postinstall scripts for dependencies you allow.
This article covers what happens when you use Bun's package manager instead of npm, when npm install takes a long time and you want to speed up dependency installs in local development or CI. I installed the same package.json with npm and Bun three times each, measured the time, and compared the generated files and the contents of node_modules.
The test environment is Ubuntu 24.04 (x86_64, 4 CPUs), Node.js 22.23.4 (npm 10.9.9), and Bun 1.4.4. For comparison, I also ran some tests with npm 11.19.1, which comes bundled with Node.js 24.22.1. The registry was the standard registry.npmjs.org, and downloads went through the proxy in my test environment. Because the times include downloads through the proxy, the numbers are only a rough guide for this environment. I did not test Windows or macOS, real CI services, projects that use workspaces, bun install --frozen-lockfile, or bun ci.
Time measured with the same package.json
I created separate folders for npm (n) and Bun (b) and put exactly the same package.json in each. The dependencies are eight packages, assuming a project that uses React and Vite.
{
"name": "bench-app",
"version": "1.0.0",
"private": true,
"type": "module",
"dependencies": {
"react": "^19.3.1",
"react-dom": "^19.3.1"
},
"devDependencies": {
"@vitejs/plugin-react": "^6.3.0",
"esbuild": "^0.28.2",
"eslint": "^10.14.0",
"typescript": "^7.0.2",
"vite": "^8.3.8",
"vitest": "^5.1.0"
}
}
I measured three scenarios. In each one, I ran npm install and bun install without any options and timed the command from start to finish.
- First run: delete the npm and Bun caches, the lockfile, and node_modules, then install
- Reinstall: delete only node_modules, keep the cache and lockfile, then install
- Run again: delete nothing and run again after the install has completed

The numbers for each of the three runs are below (in seconds).
| Scenario | npm install | bun install |
|---|---|---|
| First run | 14.98 / 15.22 / 14.83 | 3.60 / 3.69 / 3.64 |
| Reinstall | 3.64 / 4.13 / 3.76 | 0.02 / 0.03 / 0.03 |
| Run again | 0.67 / 0.72 / 0.69 | 0.01 / 0.01 / 0.01 |
In addition to installing, npm install also runs a vulnerability check (audit) and reports how many packages are looking for funding (fund). The first-run output included "3 moderate severity vulnerabilities". When I turned these off with --no-audit --no-fund, the reinstall times were 2.65 / 2.56 / 2.71 seconds. The gap with Bun is still large. The output of bun install does not include any vulnerability check results.
The first-run outputs were as follows.
$ npm install
added 119 packages, and audited 120 packages in 14s
28 packages are looking for funding
run `npm fund` for details
3 moderate severity vulnerabilities
(以下、npm audit fix の案内が続くので省略)
$ bun install
bun install v1.4.4 (38afee6c8)
Resolving dependencies
Resolved, downloaded and extracted [620]
Saved lockfile
+ @vitejs/plugin-react@6.3.0
+ esbuild@0.28.2
+ eslint@10.14.0
+ typescript@7.0.2
+ vite@8.3.8
+ vitest@5.1.0
+ react@19.3.1
+ react-dom@19.3.1
119 packages installed [3.54s]
According to the global cache section of Bun's official documentation, Bun stores downloaded packages in ~/.bun/install/cache, and when installing, it creates hard links instead of copying files into node_modules (on Linux and Windows). In my test environment too, the link count of b/node_modules/react/index.js was 2, while the same file installed with npm had a link count of 1.
$ stat -c '%h %n' n/node_modules/react/index.js b/node_modules/react/index.js
1 n/node_modules/react/index.js
2 b/node_modules/react/index.js
Installed packages and versions
I used a small script that lists the packages in node_modules as "name@version" and wrote each list to n.txt and b.txt, then compared them. Bun installed 119 packages and npm installed 121. Only the two lines below differ. All other names and versions are the same.
$ diff n.txt b.txt
24d23
< @rolldown/binding-linux-x64-musl@1.2.19
81d79
< lightningcss-linux-x64-musl@1.33.0
These two are the musl builds of the native binaries for lightningcss and rolldown, which Vite depends on. The Ubuntu test environment uses glibc, so the glibc build is the one with -gnu in its name (where libc is glibc). The -gnu builds were installed in both the npm and Bun folders.
With npm 10.9.9, the musl builds were installed only when I reinstalled from the lockfile. The first run, which had no lockfile, installed only the -gnu builds and printed "added 119 packages". When I reinstalled, the output changed to "added 121 packages". Looking at the package-lock.json from this run, the musl entries do not record libc.
node_modules/@rolldown/binding-linux-x64-gnu {"os":["linux"],"cpu":["x64"]}
node_modules/@rolldown/binding-linux-x64-musl {"os":["linux"],"cpu":["x64"]}
(lightningcss の2行も同じ形なので省略)
When I ran the same operations with npm 11.19.1, which comes bundled with Node.js 24.22.1, package-lock.json recorded entries such as "libc":["musl"], and the reinstall installed only the -gnu builds. As described in the official bun install documentation, Bun records libc in the lockfile, and on Linux it installs only the builds that match Bun's own build (the standard build targets glibc).
The lockfile becomes bun.lock
bun install does not create package-lock.json. Instead, it creates bun.lock. The file is text, and its beginning looked like this.
{
"lockfileVersion": 2,
"configVersion": 1,
"workspaces": {
"": {
"name": "bench-app",
"dependencies": {
"react": "^19.3.1",
"react-dom": "^19.3.1",
},
For the same dependencies, package-lock.json was 100,862 bytes (3,052 lines), and bun.lock was 45,686 bytes (412 lines).
The node_modules layout was, as with npm, one where most packages are placed directly under node_modules. According to the official bun install documentation on the linker setting, this layout (hoisted) is the default for new projects that do not use workspaces. For new projects that use workspaces, the default is isolated, which is similar to pnpm.
When the project has a package-lock.json
When I copied only a package.json and package-lock.json created with npm into a separate folder and ran bun install, the output was as follows.
$ bun install
bun install v1.4.4 (38afee6c8)
[2.02ms] migrated lockfile from package-lock.json
Saved lockfile
(追加したパッケージの一覧は省略)
121 packages installed [213.00ms]
Bun read package-lock.json, created bun.lock, and installed the same 121 packages as the npm install, including the two musl builds. package-lock.json was left unchanged. The official lockfile documentation also states that for projects without bun.lock, Bun automatically migrates package-lock.json and similar files, and keeps the original files.
Dependency postinstall scripts run only when allowed
The most important difference to watch for is scripts such as postinstall in dependencies. According to the official lifecycle scripts documentation, for safety, Bun only runs scripts for packages on an allowlist.
To check this, I created a package called hello-postinstall whose only job is to create postinstall-ran.txt in postinstall, packed it with npm pack, and added it as a dependency with file:.
{
"name": "hello-postinstall",
"version": "1.0.0",
"scripts": { "postinstall": "node -e \"require('fs').writeFileSync('postinstall-ran.txt','yes')\"" }
}
With npm install, the script ran and postinstall-ran.txt was created in the package folder. With bun install, it did not run. The output ended with a line starting with "Blocked 1 postinstall.".
$ bun install
bun install v1.4.4 (38afee6c8)
Resolving dependencies
Resolved, downloaded and extracted [1]
Saved lockfile
+ hello-postinstall@./hello-postinstall-1.0.0.tgz
1 package installed [3.00ms]
Blocked 1 postinstall. Run `bun pm untrusted` for details.
You can see the blocked scripts with bun pm untrusted. To allow one to run, use bun pm trust <package-name>.
$ bun pm trust hello-postinstall
bun pm trust v1.4.4 (38afee6c8)
./node_modules/hello-postinstall @./hello-postinstall-1.0.0.tgz
✓ [postinstall]: node -e "require('fs').writeFileSync('postinstall-ran.txt','yes')"
1 script ran across 1 package [35.00ms]
This added "trustedDependencies": ["hello-postinstall"] to package.json. After I deleted node_modules and ran bun install again, postinstall ran from the start.
Among the first eight dependencies, esbuild has a postinstall. However, bun pm untrusted printed "Found 0 untrusted dependencies with scripts." This is because esbuild is on Bun's built-in allowlist of commonly used packages. According to the same official documentation, if you write trustedDependencies yourself, this default list is no longer used. Packages such as esbuild and sharp that ran under the default list must also be listed if you still need them.
The official documentation also notes that postinstall is often used to prepare native binaries. If the behavior changes when you switch from npm install to bun install, first run bun pm untrusted and check whether any postinstall scripts were blocked.





