356

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.

Aurora0001
  • 10,827
  • 5
  • 47
  • 50
nikjohn
  • 16,079
  • 9
  • 45
  • 78

5 Answers5

620

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

yarn cache clean
MatthewG
  • 6,224
  • 2
  • 22
  • 27
nikjohn
  • 16,079
  • 9
  • 45
  • 78
  • 7
    In case others miss this, be certain to run this from the user account running yarn. In my case, I was trying to clean a continuous integration server with a different Windows account than the one our project builds on, and it wasn't removing files until I realized I needed to run it from that account. – daniel.caspers Jun 03 '19 at 15:33
129

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.

Jude Allred
  • 10,577
  • 7
  • 25
  • 27
MienDev
  • 1,509
  • 2
  • 8
  • 5
90

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

inga
  • 2,766
  • 1
  • 24
  • 28
KhaledMohamedP
  • 3,786
  • 2
  • 21
  • 21
  • 7
    its not always in `~/.yarn-cache/` – Pants Jan 03 '20 at 16:10
  • 2
    On my Mac the cache directory is `~/Library/Caches/Yarn/v6` as reported by the `yarn cache dir` command. – pamcevoy Feb 20 '20 at 16:26
  • I have both. `yarn cache dir` returns `~/Library/Caches/Yarn/v6`. But `~/.yarn-cache/` is 2.8GB and hasn't been updated since January 2018. `yarn cache clean` _**does not work**_ on `~/.yarn-cache/`. It has to be manually deleted. Cache location seems to be a tumultuous subject https://github.com/yarnpkg/yarn/search?q=.yarn-cache&type=Commits – mccallofthewild May 06 '20 at 02:54
33

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.

Dan K.K.
  • 4,999
  • 2
  • 26
  • 33
0

When I want to start fresh I run those set of commands:

yarn cache clean ; rm -rf ./node_modules; yarn --no-lockfile
Oded BD
  • 1,367
  • 12
  • 20