If you use pnpm, its content-addressable store helps save disk space and speed up installs by reusing package files across projects. Over time, the store can contain packages that your current projects no longer need. To clean it up, run pnpm store prune. If you want to remove the entire store instead, first find its location with pnpm store path, then delete that directory. The best option depends on whether you want to remove only unused packages or clear pnpm’s local package cache completely.
This guide explains how to clear the pnpm store safely, what each cleanup method removes, and what to expect the next time you install dependencies.
How Do I Clear the pnpm Store?
For most users, the recommended command is:
pnpm store prune
Run it from any directory where pnpm is available. The command removes package content from the store when pnpm determines that it is no longer referenced by projects on your system. It does not delete your project files or remove dependencies from your projects’ node_modules directories.
For example, open a terminal and run:
pnpm store prune
Depending on your pnpm version, the command may display a summary of the content it removed. If there is nothing to clean up, it may finish without removing anything. Pruning is generally the right choice when you want to reclaim space without wiping the entire store.
What Is the pnpm Store?
The pnpm store is a shared local cache for package files. When you install a dependency, pnpm can save its content in the store and link it into your project. This lets multiple projects on the same machine reuse package files instead of keeping a fully separate copy of every package for every project.
Because the store is shared, deleting a project does not necessarily remove its package content from the store immediately. That content can remain available for other projects or for future installs. Over time, packages used by projects you no longer maintain may also remain cached, which is why pruning can help recover disk space.
The store is separate from a project’s dependency declarations and lockfile. Clearing stored package content does not change your package.json or pnpm-lock.yaml. If a project needs a package again after its content has been removed, pnpm can fetch it again during a later install.
How to Find the pnpm Store Location
Before deleting the store manually, find out where pnpm keeps it on your machine. Run:
pnpm store path
pnpm prints the path to the active store. The exact location depends on your operating system, pnpm version, and configuration, so use the path shown by your own command rather than assuming it is in a particular folder.
You can also check whether you have configured a custom store directory:
pnpm config get store-dir
If the command returns a path, pnpm may be using that configured location. If it does not show a custom path, use pnpm store path to see the active store directory. This is especially useful if you have changed pnpm configuration or use multiple development environments.
How to Completely Clear the pnpm Store
Pruning removes content pnpm considers unnecessary. To clear the store entirely, close active development tools and terminal processes that may be installing packages, run pnpm store path, and remove the directory that command reports.
Use your operating system’s file manager if you want to review the target carefully before deleting it. You can also remove the directory from a terminal, but take care to substitute the exact path printed by pnpm. Do not run a broad deletion command against a guessed path or a parent directory: deleting the wrong folder can remove unrelated files.
After the store is deleted, pnpm will recreate it as needed. The next install may take longer because packages must be downloaded again rather than reused from the local cache. Clearing the store does not normally require you to remove project-level node_modules folders.
Choose full deletion only when you specifically need a fresh store, want to remove all cached package content, or are troubleshooting a suspected problem with cached data. For routine disk-space cleanup, pnpm store prune is usually safer and more convenient.
Pruning the Store vs. Deleting It
These cleanup methods have different effects. Use the one that matches your goal:
-
Run
pnpm store prune: Removes package content pnpm considers unreferenced while keeping reusable store content. - Delete the store directory: Removes all cached package content, including packages that current projects may need to download again.
-
Delete a project’s
node_modulesdirectory: Removes that project’s installed dependency links and files, but does not necessarily clear the shared store.
In most cases, start with pruning. If you are trying to fix a problem with one project, deleting that project’s node_modules and reinstalling may be more appropriate than clearing the shared store used by every project.
When Should You Run pnpm Store Prune?
There is no need to prune the pnpm store after every install. Consider running it when you have removed or archived projects, need to free disk space, or want to clean up package content that is no longer useful to your active work.
Pruning can also be useful on a machine with limited storage, such as a small development laptop or a build environment with a restricted disk quota. However, removing cached content can mean slower installs later, because pnpm may need to download packages again.
For a routine cleanup, run the command directly:
pnpm store prune
There is generally no benefit to running it repeatedly in a short period unless your projects or dependencies have changed significantly. If you share a machine with other developers or use automated build processes, consider whether their work relies on the same store before manually deleting the full directory.
What Happens After You Clear the Store?
Clearing cached content does not remove your dependency list, lockfile, or application source code. Your project still records its dependencies in its manifest and lockfile. When you run an install, pnpm checks what the project needs and obtains any missing package content.
Because the cache is empty or smaller, the first install after full deletion may require more network activity and take longer. Once packages are fetched again, pnpm can store and reuse them. If you only prune unused content, packages still needed by your projects can remain available in the store.
If an install fails after cleanup, check the error message, confirm that your network connection and package registry are available, and try running pnpm install again. The cleanup itself does not update your dependencies or change the versions recorded in the lockfile.
Troubleshooting pnpm Store Cleanup
If pnpm store prune is not recognized, check that pnpm is installed and available in your terminal. You can check the version with:
pnpm --version
If you work with multiple pnpm versions, use the same pnpm setup you normally use for your projects. The store path and command behavior can depend on the active installation and configuration.
If the store does not seem to be shrinking, first confirm the active location with pnpm store path. You may have more than one store directory, particularly if you have used different pnpm installations, configured a custom directory, or worked in separate environments. Also remember that pruning removes content pnpm considers unreferenced; it is not the same as deleting every cached package.
If you receive a permission error while removing the store manually, do not immediately run the terminal as an administrator or root. Verify the directory path and check which process or user owns it. Use the appropriate permissions for your system, and avoid changing permissions on unrelated folders.
Frequently Asked Questions
Does pnpm store prune delete my project dependencies? No. The command cleans the shared store; it does not remove dependency declarations from package.json or delete your project’s installed dependencies.
Will clearing the store break my projects? Clearing cached content does not normally change a project’s configuration. If a project needs content that is no longer stored locally, pnpm can download it again during installation. You will need registry access for packages that must be fetched.
Can I delete the pnpm store while an install is running? Avoid doing so. Let installs and other pnpm operations finish before deleting the store manually. Removing files while a process is using them can cause errors or leave an operation incomplete.
Does pnpm automatically clean the store? pnpm manages package content and provides pnpm store prune for cleanup. If you want to reclaim space, run the prune command yourself or remove the store directory when you intentionally want a complete reset.
Should I clear the store to update a dependency? Usually not. Update dependencies using your normal pnpm workflow. Clearing the store is a cache cleanup, not a way to change dependency versions.
Conclusion
The simplest way to clear unused pnpm store content is to run pnpm store prune. It removes content pnpm no longer considers necessary without deleting your project files or dependency declarations. If you need to erase every cached package, use pnpm store path to locate the active store and carefully remove that directory instead.
For everyday maintenance, pruning is the recommended starting point. Save full store deletion for situations where you need a completely fresh cache, and expect future installs to take longer as pnpm downloads the required packages again.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.