Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the cache path for npm (or completely disable the cache) on Windows?

Tags:

node.js

npm

People also ask

How do I change the location of npm cache?

You can also set an environment variable with export npm_config_cache=/path/to/cache (Unix) or set npm_config_cache=C:\path\to\cache (Win) as an alternative to npm config set (this is true for all config options in npm). Show activity on this post.

How do I disable npm cache?

skips cache when requesting from the registry. Maybe use -f / --force is the simplest way to disable npm cache.

Where is npm cache located Windows?

Cache files are stored in ~/. npm on Posix, or %AppData%/npm-cache on Windows.

Can I delete npm cache folder?

Yes it is safe, I have deleted npm and npm-cache folder manually and reinstall node its working fine.


You can change npm cache folder using the npm command line. (see https://docs.npmjs.com/cli/v6/using-npm/config#cache)

So you might want to try this command :

> npm config set cache C:\Devel\nodejs\npm-cache --global 

You can also set an environment variable with export npm_config_cache=/path/to/cache (Unix) or set npm_config_cache=C:\path\to\cache (Win) as an alternative to npm config set (this is true for all config options in npm).


For anyone using docker you can add the env var at runtime with:

docker run -e npm_config_cache=/path/to/cache mydockerimage:tag

You can also do following:

For having cache path as you wish, for a single package while installing it:

npm install packageName --cache path/to/some/folder

For having cache path as you wish, for all the packages in package.json:

Just be in the directory where package.json is as usual and do

npm install --cache path/to/some/folder

You may not find this in npm documentation but i have tried it with npm 6 and it works. Looks like it works since npm 5 [Refer: How to specify cache folder in npm5 on install command?


In Windows you can simply cd to the desired cache folder and do npm set cache --global