JavaScript

How to clear the global npx cache

Advertisements

I have been using npx a lot lately, especially whenever I want to use a CLI tool. It is an excellent alternative to installing packages globally since it installs them in a temporary cache instead.

Even though it is installed in a temporary location, I figured it is a good idea to clear the cache once in a while. To do so, we can run the following command on a Mac:

rm -rf ~/.npm/_npx
Bash

And if we were on a Windows machine:

del /q /s %LocalAppData%/npm-cache/_npx
Bash

If npx cache is not located at one of these locations and we want to find the exact location for it, we can also use the following command to do so.

npm config get cache
Bash

And that is it. The command will clear the global npx cache and we can then install a new version if we want to do so or just have a clean slate to begin with. If you have any questions, do let us know in the comments below.

Saransh Kataria

Born in Delhi, India, Saransh Kataria is the brain behind Wisdom Geek. Currently, Saransh is a software developer at a reputed firm in Austin, and he likes playing with new technologies to explore different possibilities. He holds an engineering degree in Computer Science. He also shares his passion for sharing knowledge as the community lead at Facebook Developer Circle Delhi, NCR which is a developer community in Delhi, India.

Share
Published by
Saransh Kataria

Recent Posts

Generating a QR code using Node.js

I was preparing a slide deck for a hackathon and decided to put in a…

2 weeks ago

Copy/Pasting output from the terminal

Manually copy-pasting the output of a terminal command with a mouse/trackpad feels tedious. It is…

1 month ago

How To Get The Hash of A File In Node.js

While working on a project, I wanted to do an integrity check of a file…

2 months ago

Native popover API in HTML

Popovers have been a problem that was typically solved by using a third-party solution. But…

2 months ago

Node.js 20.6 adds built-in support for .env files

Node.js 20.6 added built-in support for the .env file. This is an excellent addition to the platform…

3 months ago

Object destructuring in TypeScript

Object destructuring is a powerful ES 6 feature that can help developers write cleaner code.…

3 months ago
Advertisements