Skip to content

How to Clear the Global npx Cache

how to clear the global npx ache

If you actively use npx, you may have quite a bunch of cached packages on your machine.

These cached packages can accumulate over time and consume significant disk space.

It’s a good practice to clear the cache occasionally as this also helps you prevent version conflicts.

At the time of writing this post, there is still no native npx command to clear the cache.

Nevertheless, I’ll show you a few methods to quickly and easily clear the npx cache on Windows, Linux, and macOS.

Let’s get started!

🎥 Do you prefer video tutorials more? I got just the thing for you:

Cache location

If you don’t know where the npx cache is located, you can run the following command:

npm get cache

This command shows you where the npm cache directory is. The npx cache is right inside it.

If you’re on Linux or macOS and curious to find out how much disk space the npx cache takes, you can run this command:

du -hd1 ~/.npm/_npx

npm cache disk usage on linux
npm cache disk usage on Linux

Clear npx cache

Let’s see how to clear the npx cache.

Windows

If you are on a Windows machine, you can run the following command from the Command Prompt:

rd /q /s %LocalAppData%\npm-cache\_npx

This will delete the _npx directory including everything inside it. It does it quietly so you don’t have to respond to the confirmation prompt.

If you don’t want to use the Command Prompt, you can also use PowerShell:

Remove-Item -Path "$env:LocalAppData\npm-cache\_npx" -Recurse -Force

Linux & macOS

Let’s now see how you can delete the npx cache on a Linux and macOS machine:

Find the npm cache location:

npm get cache

Run the following command to make sure the _npx folder is there before you delete it.

ls ~/.npm

Run the following command to delete the cache:

rm -rf ~/.npm/_npx

You can inspect again the .npm folder to make sure that the npx cache is gone.

That’s all 💜

I hope you were able to clear the npx cache successfully and that you also gained valuable insights into the npx and npm ecosystems.


Let me know what you think about this article in the comments section below.

If you find this article helpful, please share it with others and subscribe to the blog to support me, and receive a bi-monthly-ish e-mail notification on my latest articles.   
  

Comments