Clear cache in Yarn: yarn cache clean

Clear cache in Yarn: yarn cache clean

📋 Table Of Content

In this article, we will learn why and how to clear cache in yarn from your local storage.

Yarn (Yet Another Resource Negotiator) is a package manager just like npm to manage our node project dependencies. It's an open-source project created by Facebook to fix security and performance issues with npm.

Whenever we install any node packages using the yarn install command, it creates a cached copy of the package in our ~/.cache/yarn directory.

You can use the yarn cache dir command to find out the path to your cache directory in your system.

The Yarn package manager utilizes the cache files to optimize the installation process of the dependencies in our project. It directly installs the packages from the cache directory to our project folders, thereby saving time and internet usage.

However, since the cached files are not deleted automatically by the package managers, the package files get piled up with unused data and so the yarn cache takes up a lot of space in our local storage.

So it is better to clean the cache folder sometimes to avoid any error in package installations too.

Clear cache in Yarn

To clear the cache directory in yarn, we just have to use the yarn cache clean command in our terminal.

yarn cache clean

This command deletes all data stored in our cache directory.

Now, if you don't want to clear all data from the cache folder, just some specific packages then you can use the yarn cache clean command along with the package name.

yarn cache clean <package name>

For example, I want to delete the flickity package from the cache, so it will write.

yarn cache clean flickity

You can also check the list of all the stored cached packages in your cache directory, you can use the command:

yarn cache list

It will list out all the name of the stored packages in your cache folder and then you can select the name of the unused package and delete it manually.

Related Topics:

Uninstall/Remove package using Yarn

How to clean cache in npm?