How to clear cache in Yarn?

Yarnpkg

Yarnpkg Problem Overview


I am doing some benchmark tests for Facebook's Yarn. For this, I need to clear my global Yarn cache.

Is there a command available for this? I have force-removed my ~/.yarn-cache folder, but this seems to be quite manual.

Yarnpkg Solutions


Solution 1 - Yarnpkg

Ok I found out the answer myself. Much like npm cache clean, Yarn also has its own

yarn cache clean

Solution 2 - Yarnpkg

Run yarn cache clean.


Run yarn help cache in your bash, and you will see:

>Usage: yarn cache [ls|clean] [flags] > > Options: > -h, --help output usage information > -V, --version output the version number > --offline
> --prefer-offline
> --strict-semver
> --json
> --global-folder [path]
> --modules-folder [path] rather than installing modules into the node_modules folder relative to the cwd, output them here
> --packages-root [path] rather than storing modules into a global packages root, store them here
> --mutex [type][:specifier] use a mutex to ensure only one yarn instance is executing
> > Visit http://yarnpkg.com/en/docs/cli/cache for documentation about this command.

Solution 3 - Yarnpkg

Also note that the cached directory is located in ~/.yarn-cache/:

yarn cache clean: cleans that directory

yarn cache list: shows the list of cached dependencies

yarn cache dir: prints out the path of your cached directory

Solution 4 - Yarnpkg

In addition to the answer, $ yarn cache clean removes all libraries from cache. If you want to remove a specific lib's cache run $ yarn cache dir to get the right yarn cache directory path for your OS, then $ cd to that directory and remove the folder with the name + version of the lib you want to cleanup.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnikjohnView Question on Stackoverflow
Solution 1 - YarnpkgnikjohnView Answer on Stackoverflow
Solution 2 - YarnpkgMienDevView Answer on Stackoverflow
Solution 3 - YarnpkgKhaledMohamedPView Answer on Stackoverflow
Solution 4 - YarnpkgDan K.K.View Answer on Stackoverflow