LinuxCommandLibrary

npm-cache

Manages the npm package cache

TLDR

Add a specific package to the cache

$ npm cache add [package_name]
copy

Remove a specific package from the cache
$ npm cache remove [package_name]
copy

Clear a specific cached item by key
$ npm cache clean [key]
copy

Clear the entire npm cache
$ npm cache clean --force
copy

List the contents of the npm cache
$ npm cache ls
copy

Verify the integrity of the npm cache
$ npm cache verify
copy

Show the cache path
$ npm config get cache
copy

Change the cache path
$ npm config set cache [path/to/directory]
copy

SYNOPSIS

npm cache clean [--force]
npm cache verify

PARAMETERS

clean
    Removes all data from the npm cache.

--force
    When used with `clean`, bypasses confirmation prompts and forcefully removes the cache. Use with caution!

verify
    Verifies the integrity of the cache, ensuring that cached data is not corrupted.

DESCRIPTION

The `npm cache` command is used to manage the local npm package cache. This cache stores downloaded packages to avoid redundant downloads when installing or updating dependencies. Managing the cache can free up disk space, resolve installation issues caused by corrupted cache data, and ensure that you're using the correct versions of packages. Commands like `npm cache clean` remove all cached data or specific packages, while `npm cache verify` checks the integrity of the cache. The npm cache is crucial for offline installations and significantly speeds up package installations by reusing previously downloaded packages. Understanding how to use `npm cache` is vital for optimizing your npm workflow and troubleshooting package installation problems. Properly managing the cache can prevent errors caused by outdated or corrupted data, ensuring your projects consistently use the desired package versions.

CAVEATS

The `npm cache` is located by default in a platform-specific directory, but the location can be modified using the cache configuration option in npmrc. Always be careful when using npm cache clean --force, as it removes everything from the cache, potentially slowing down future installations if network conditions are poor.

CACHE LOCATION

The default cache location depends on the operating system. You can find the current cache location using npm config get cache. It can be changed by setting the cache configuration option with npm config set cache /path/to/new/cache.

TROUBLESHOOTING INSTALLATION ISSUES

If you encounter issues installing packages, running npm cache clean --force followed by npm install can often resolve problems caused by a corrupted or outdated cache.

HISTORY

The `npm cache` command has been a core part of npm since its early versions, evolving alongside the npm ecosystem. Initially focused on basic caching functionality to reduce download times, it later incorporated features like verification to enhance reliability. Over time, the command has been refined to address common user issues, such as disk space management and cache corruption, leading to its current set of functionalities. Its development mirrors the growing complexity and sophistication of Node.js package management.

SEE ALSO

npm(1), npm config(1), npm install(1)

Copied to clipboard