How to Check Installed Packages and the Cache with bun pm
bun pm ls lists the packages installed through Bun and their versions. bun pm cache shows where Bun keeps the packages it has downloaded, the cache. Use these to check which version is in node_modules, or to clear the cache when disk space runs low.
I created a small project with Express in a test environment, then checked how to print the list, what the cache contains and how much space it uses, and what happens when the cache is cleared.
The test environment was Ubuntu 24.04 (x86_64) with Bun 1.4.4. On 2026-11-24, I fetched packages from the default registry (registry.npmjs.org). I set HOME to an empty folder, so the cache started empty. In the output, the working folder is shown as /path/to/. I did not test monorepos that use workspaces, the global store (globalStore = true), bun pm cache pack and unpack, or Windows and macOS.
- 1. The test project
- 2. List installed packages with bun pm ls
- 3. Find the installed versions of a package by name
- 4. View packages installed with bun add -g
- 5. Check the cache location and contents with bun pm cache
- 6. Cache size and how it relates to node_modules
- 7. Remove old packages only with bun pm cache prune
- 8. Remove the whole cache with bun pm cache rm
- 9. Refill the cache with bun pm fetch
The test project
I started with an empty package.json and ran bun add express@4.21.2 and bun add -d typescript@5.6.3. The output of bun add showed 69 packages installed the first time and 1 the second time. The package.json is shown below.
{
"name": "pm-app",
"version": "1.0.0",
"private": true,
"dependencies": {
"express": "4.21.2"
},
"devDependencies": {
"typescript": "5.6.3"
}
}
List installed packages with bun pm ls
bun pm ls shows the dependencies written in package.json (direct dependencies) and the versions actually installed. As the official bun pm documentation describes, bun list gave the same result.
$ bun pm ls
/path/to/pm-app node_modules (70 installed)
├── express@4.21.2
└── typescript@5.6.3
The "70 installed" on the first line includes indirect dependencies. Only two packages are listed, but node_modules also contains the packages that Express uses.
Show indirect dependencies with –all
With --all, every package is listed, including indirect dependencies. The first and last lines are shown below.
$ bun pm ls --all | head -12
/path/to/pm-app node_modules
├── accepts@1.3.8
├── array-flatten@1.1.1
├── body-parser@1.20.3
├── bytes@3.1.2
├── call-bind-apply-helpers@1.0.2
├── call-bound@1.0.4
├── content-disposition@0.5.4
├── content-type@1.0.5
├── cookie@0.7.1
├── cookie-signature@1.0.6
├── debug@2.6.9
$ bun pm ls --all | tail -3
├── unpipe@1.0.0
├── utils-merge@1.0.1
└── vary@1.1.2
With --all, the first line did not show a count. wc -l counted 71 lines, and the 70 lines after the first line match the "70 installed" above. The output does not show which package depends on which. All packages are listed flat, sorted by name.
Exclude devDependencies with –production
With --production, devDependencies and the packages used only by them are left out. In this example, typescript was removed and the count dropped to 69.
$ bun pm ls --production
/path/to/pm-app node_modules (69 installed)
└── express@4.21.2
According to the official documentation, --omit=dev has the same effect. The output of bun pm ls --all --omit=dev also did not include typescript.
Find the installed versions of a package by name
If you pass a package name to bun pm ls, it prints every installed version of that package, whether or not it is a direct dependency. ms is not written in package.json, but I found that two versions were installed.
$ bun pm ls ms
/path/to/pm-app node_modules
├── ms@2.0.0
└── ms@2.1.3
Looking in node_modules, 2.0.0 was in node_modules/ms and 2.1.3 was in node_modules/send/node_modules/ms. To see which package requires each version, use bun why ms (the bun why description in the Bun repository).
If you pass a name that is not installed, you get an error and the exit code is 1. You can use this in shell scripts to check whether a package is installed.
$ bun pm ls no-such-package
/path/to/pm-app node_modules
error: no packages match: no-such-package
View packages installed with bun add -g
Packages installed globally with bun add -g are listed by bun pm ls -g. I tested it with is-number.
$ bun pm ls -g
/path/to/home/.bun/install/global node_modules (1 installed)
└── is-number@7.0.0
bun pm bin shows the folder where command files go. With -g, it shows the folder for the commands of globally installed packages.
$ bun pm bin
/path/to/pm-app/node_modules/.bin
$ bun pm bin -g
/path/to/home/.bun/bin
Check the cache location and contents with bun pm cache
Bun stores packages it downloads from the registry in the cache. The next install puts them into node_modules from there. bun pm cache shows the cache location.
$ bun pm cache
/path/to/home/.bun/install/cache
According to the official cache documentation, the default location is ~/.bun/install/cache, and you can change it with the environment variable BUN_INSTALL_CACHE_DIR. When I ran it with BUN_INSTALL_CACHE_DIR set, bun pm cache printed that location.
$ BUN_INSTALL_CACHE_DIR=/path/to/other-cache bun pm cache
/path/to/other-cache
The same documentation says each package goes into a folder named name@version. In my test environment, the folder names had @@@1 appended. ms, which has two installed versions, has two folders.
$ ls -d "/path/to/home/.bun/install/cache"/ms@* "/path/to/home/.bun/install/cache"/express@*
/path/to/home/.bun/install/cache/express@4.21.2@@@1
/path/to/home/.bun/install/cache/ms@2.0.0@@@1
/path/to/home/.bun/install/cache/ms@2.1.3@@@1
The cache folder contained 209 entries. Of these, 71 package folders ended in @@@1. That is the 70 project packages plus the 1 globally installed is-number. There were also 69 files with the .npm extension, and folders named only by package name, such as ms. Inside the ms folder are symbolic links to the per-version folders.
Cache size and how it relates to node_modules
You can measure the cache size with du. In this example, it was 29 MB.
$ du -sh "/path/to/home/.bun/install/cache"
29M /path/to/home/.bun/install/cache
node_modules alone measures 26 MB, which makes it look as if the same packages are stored twice. However, when I measured the cache and node_modules together in one du run, node_modules added only 572 KB.
$ du -sh "/path/to/home/.bun/install/cache" node_modules
29M /path/to/home/.bun/install/cache
572K node_modules
Using stat to show the inode number (the number that identifies a file on disk) and the link count, I found that ms in node_modules and ms in the cache had the same inode number, with a link count of 2. Both are hard links to the same data on disk. This sharing is why the combined du reported a small size for node_modules. The official documentation also says that on Linux and Windows, packages are hard-linked from the cache into node_modules (on macOS, it uses clonefile).
$ stat -c '%h %i %n' node_modules/ms/index.js "/path/to/home/.bun/install/cache/ms@2.0.0@@@1/index.js"
2 697954 node_modules/ms/index.js
2 697954 /path/to/home/.bun/install/cache/ms@2.0.0@@@1/index.js

This means that on Linux, clearing the cache does not free the disk space that node_modules uses. Only the space for packages that no project uses is freed.
Remove old packages only with bun pm cache prune
To delete only old packages instead of the whole cache, use bun pm cache prune. According to the official documentation, packages older than 30 days are targeted by default, and you can change the number of days with --max-age. With --dry-run, it only lists what would be deleted and deletes nothing.
$ bun pm cache prune --dry-run
Done! Checked 71 packages, none older than 30 days (nothing to prune)
Since the packages had just been downloaded, none were older than 30 days. With --max-age 0, all 71 packages were targeted.
$ bun pm cache prune --max-age 0 --dry-run | head -3
- qs@6.13.0@@@1
- finalhandler@1.3.1@@@1
- ms@2.1.3@@@1
$ bun pm cache prune --max-age 0 --dry-run | tail -2
71 packages older than 0 days can be removed (checked 71)
Run without --dry-run to remove them.
According to the same documentation, "age" here means the time since Bun downloaded the package. On environments that record file access times, such as Linux with the default relatime setting, it means the time since the cache was last linked during an install. The documentation also says that package metadata (manifests) and packages fetched from git are not removed by prune.
Remove the whole cache with bun pm cache rm
bun pm cache rm deletes everything in the cache folder. With --dry-run, it only printed the location to be deleted. After running it with --dry-run, the 209 cache entries were still there.
$ bun pm cache rm --dry-run
dry run: would delete 'bun install' cache at /path/to/home/.bun/install/cache
Would clear 0 cached 'bunx' packages
You cannot choose a single package to delete. Passing a name gave an error.
$ bun pm cache rm ms
error: unexpected argument "ms"
usage: bun pm cache [rm | prune | pack <file> | unpack <file>]
When I ran it without --dry-run, the cache folder became empty. The link count of ms in node_modules dropped from 2 to 1, but the file itself remained. Running require on express with bun -e loaded it without problems.
$ bun pm cache rm
Cleared 'bun install' cache
Cleared 0 cached 'bunx' packages
$ ls -A "/path/to/home/.bun/install/cache" | wc -l
0
$ stat -c '%h %n' node_modules/ms/index.js
1 node_modules/ms/index.js
$ bun -e "console.log(typeof require('express'))"
function
After you clear the cache, the next bun install downloads the required packages from the registry again (official documentation). If you use bun install --offline on a machine without internet access, after clearing the cache, you need to run bun pm fetch (described in the next section) on a machine with internet access to refill it (the bun pm fetch section of the same documentation).
Refill the cache with bun pm fetch
You can refill a cache you have cleared with bun pm fetch. According to the official bun pm fetch documentation, it downloads only the packages listed in bun.lock that are missing from the cache, and it does not create node_modules. With --dry-run, it showed only how many packages were missing.
$ bun pm fetch --dry-run
bun pm fetch v1.4.4 (38afee6c8)
Would fetch 70 packages into cache [1.00ms]
Cache: /path/to/home/.bun/install/cache
$ bun pm fetch
bun pm fetch v1.4.4 (38afee6c8)
Fetching packages
Fetched 70 packages into cache [5.17s]
Cache: /path/to/home/.bun/install/cache
It refetched the 70 project packages. The globally installed is-number was not fetched. The same documentation says that packages installed globally are fetched with bun pm fetch -g.





