codekingpro/portable-devtools
114k
1---
2title: npm-cache
3section: 1
4description: Manipulates packages cache
5---
6
7### Synopsis
8
9```bash
10npm cache add <package-spec>
11npm cache clean [<key>]
12npm cache ls [<name>@<version>]
13npm cache verify
14npm cache npx ls
15npm cache npx rm [<key>...]
16npm cache npx info <key>...
17```
18
19Note: This command is unaware of workspaces.
20
21### Description
22
23Used to add, list, or clean the `npm cache` folder.
24Also used to view info about entries in the `npm exec` (aka `npx`) cache folder.
25
26#### `npm cache`
27
28* add:
29 Add the specified packages to the local cache.
30 This command is primarily intended to be used internally by npm, but it can provide a way to add data to the local installation cache explicitly.
31
32* clean:
33 Delete a single entry or all entries out of the cache folder.
34 Note that this is typically unnecessary, as npm's cache is self-healing and resistant to data corruption issues.
35
36* ls:
37 List given entries or all entries in the local cache.
38
39* verify:
40 Verify the contents of the cache folder, garbage collecting any unneeded data, and verifying the integrity of the cache index and all cached data.
41
42#### `npm cache npx`
43
44* ls:
45 List all entries in the npx cache.
46
47* rm:
48 Remove given entries or all entries from the npx cache.
49
50* info:
51 Get detailed information about given entries in the npx cache.
52
53### Details
54
55npm stores cache data in an opaque directory within the configured `cache`, named `_cacache`.
56This directory is a [`cacache`](http://npm.im/cacache)-based content-addressable cache that stores all http request data as well as other package-related data.
57This directory is primarily accessed through `pacote`, the library responsible for all package fetching as of npm@5.
58
59All data that passes through the cache is fully verified for integrity on both insertion and extraction.
60Cache corruption will either trigger an error, or signal to `pacote` that the data must be refetched, which it will do automatically.
61For this reason, it should never be necessary to clear the cache for any reason other than reclaiming disk space, thus why `clean` now requires `--force` to run.
62
63There is currently no method exposed through npm to inspect or directly manage the contents of this cache.
64In order to access it, `cacache` must be used directly.
65
66npm will not remove data by itself: the cache will grow as new packages are installed.
67
68### A note about the cache's design
69
70The npm cache is strictly a cache: it should not be relied upon as a persistent and reliable data store for package data.
71npm makes no guarantee that a previously-cached piece of data will be available later, and will automatically delete corrupted contents.
72The primary guarantee that the cache makes is that, if it does return data, that data will be exactly the data that was inserted.
73
74To run an offline verification of existing cache contents, use `npm cache verify`.
75
76### Configuration
77
78#### `cache`
79
80* Default: Windows: `%LocalAppData%\npm-cache`, Posix: `~/.npm`
81* Type: Path
82
83The location of npm's cache directory.
84
85
86
87### See Also
88
89* [package spec](/using-npm/package-spec)
90* [npm folders](/configuring-npm/folders)
91* [npm config](/commands/npm-config)
92* [npmrc](/configuring-npm/npmrc)
93* [npm install](/commands/npm-install)
94* [npm publish](/commands/npm-publish)
95* [npm pack](/commands/npm-pack)
96* [npm exec](/commands/npm-exec)
97* https://npm.im/cacache
98* https://npm.im/pacote
99* https://npm.im/@npmcli/arborist
100* https://npm.im/make-fetch-happen
101 