DevCleaner
Menu
Skip to content
Browse guides

How to Clear the npx Cache on Mac and Linux

When you run npx some-tool and the tool is not in your project, npm installs it into a folder inside its cache and runs it from there. That folder is _npx, and it stays after the command finishes. It is also not the part of the cache that npm cache clean --force removes, which is why many people clear "the npm cache" and still find npx packages on disk.

On this page

Where the npx cache lives

npm keeps everything under one cache directory. On macOS and Linux the default is ~/.npm. Inside it, the parts that matter here are:

  • ~/.npm/_npx/: one folder per npx install, named with a short hash. Each holds a package.json, a package-lock.json and a node_modules folder with the tool and its dependencies.
  • ~/.npm/_cacache/: the package download cache that npm install and npx both read from. This is what npm cache clean --force deletes.
  • ~/.npm/_logs/: debug logs from failed npm commands.

If you changed the cache location in .npmrc or with the npm_config_cache variable, everything moves with it. Ask npm where it is:

npm config get cache

Measure it first

This only reads sizes:

du -sh "$(npm config get cache)"/_npx "$(npm config get cache)"/_cacache

On npm 11.2.0 or newer you can also see which tools are in the npx cache:

npm --version
npm cache npx ls

Each line shows a key (the folder name) and the package it holds, for example 8f497369b2d6166e: cowsay. To see the exact version and location of one entry:

npm cache npx info <key>

Clear the npx cache (npm 11.2.0 and newer)

Remove a single entry when one tool is stuck on an old version or broken:

npm cache npx rm <key>

Remove the whole npx cache:

npm cache npx rm --force

npm asks for --force when you remove everything, the same as it does for npm cache clean. Nothing in your projects changes. The next time you run one of those tools with npx, npm installs it again.

Clear the npx cache on older npm versions

npm versions before 11.2.0 do not have the npm cache npx commands. Delete the folder yourself:

rm -rf "$(npm config get cache)/_npx"

Quote the path as shown, so a space in a custom cache path does not split the command. Upgrading npm (npm install -g npm@latest) gives you the built-in commands, but check that the new npm supports your Node.js version first. npm prints a warning when it does not.

Clear the npm download cache too

If you want the space back from both parts, run the npm command as well:

npm cache clean --force

This deletes _cacache only. It does not delete _npx and it does not touch node_modules in your projects. npm cache verify is the gentler option: it checks the download cache and removes data npm no longer needs, and it also leaves _npx alone. The npm cache guide covers this part in more detail.

When npx runs an old version

npx reuses what it already installed when that matches what you asked for. If a scaffolding tool keeps giving you an old template, ask for the version you want:

npx create-vite@latest

If that still picks up the old copy, find its key with npm cache npx ls and remove that one entry. You do not need to clear the whole cache to fix a single tool.

Before you delete: check what is running

Desktop apps often start tools through npx. MCP servers set up in Claude Desktop, Cursor and other AI tools are commonly configured as npx -y <package>, so they run straight from _npx. Quit those apps, or stop the server, before you remove the folder. When they start again, npx installs the server again, which needs a network connection.

If you work offline, keep the entries you need. Without the folder and without the download cache, npx cannot run a tool until it can reach the registry.

The easier option: DevCleaner

DevCleaner is an app for macOS and Linux that measures developer caches and sorts them by risk. Its Node.js section lists the npx cache as its own row, next to the npm download cache and npm logs, all rated Safe. It shows the size before you clean, and because the rows are Safe they are part of Quick Clean. DevCleaner clears every entry inside the _npx folder. It does not pick out single entries, so use npm cache npx rm <key> for that.

On macOS, DevCleaner looks at the default ~/.npm location. On Linux it also follows NPM_CONFIG_CACHE or npm_config_cache when the value is an absolute path. If you moved the cache with .npmrc, use the commands above.

It also helps when npx is only part of the problem. The same scan covers old node_modules folders, the Yarn and pnpm caches, Xcode builds and Docker. The free version scans everything and cleans Safe items. Pro is $19.99 a year or $59 lifetime and covers up to 3 devices (Mac or Linux). A 14-day Pro trial does not charge a card and does not start a subscription.

FAQ

Is it safe to delete ~/.npm/_npx?
Yes, as long as nothing is running from it. It only holds tools that npx installed for one-off runs. Your projects and their node_modules folders are separate. npx installs a tool again the next time you run it.
Does npm cache clean --force clear the npx cache?
No. It deletes _cacache inside the npm cache directory. The _npx folder stays. Use npm cache npx rm --force on npm 11.2.0 or newer, or delete the _npx folder on older versions.
Where is the npx cache on Windows?
The npm cache defaults to %LocalAppData%\npm-cache, so the npx folder is %LocalAppData%\npm-cache\_npx. The npm cache npx commands work the same way there.
Will clearing the npx cache break my global packages?
No. Packages installed with npm install -g live in npm's global prefix, not in the cache. Run npm root -g to see where they are.

Scan it with DevCleaner

DevCleaner lists the npx cache as its own Safe row in the Node.js section and shows the size before you clean.

Download DevCleaner ↓

References and scope

Checked against npm 12.2.1, the latest release on October 27, 2026, and npm 10.9.0. Paths are for macOS and Linux with the default cache location.

Featured on TryMacApps Featured on UsefulShelf Featured on Formac Listed on MacTools Pro Fazier badge