Clear pip Cache Safely

In this tutorial, we want to teach you to Clear the pip cache Safely in Linux. As you know, pip is the package manager for Python. With this utility, you can manage your Python packages from the command line interface. Pip uses a cache mechanism that lets you download and install Python packages faster. In some cases, pip may not need to redownload a package when updating if it already exists in the cache. So for this reason you can clear your pip cache.

Steps To Clear Pip Cache Safely in Linux

To complete this guide, you can follow the steps below to manage the pip cache using various commands, and how to clear it in Linux.

Step 1 – Pip Cache Syntax Command

The pip cache command in the version of pip 20 and higher is as shown below:

pip cache subcommands

The Subcommands in the pip cache are listed below:

  • dir: Show the cache directory.
  • info: Show information about the cache.
  • list: List filenames of packages stored in the cache.
  • remove: Remove one or more packages from the cache.
  • purge: Remove all items from the cache.

Step 2 – Where is the pip cache directory located in Linux?

If you are looking for your cache directory, you can use the dir subcommand. To do this, run the following pip cache command:

pip cache dir

In your output, you should see your pip cache directory on your Linux.

Also, pip provides us with the command to view the filenames and directories stored in the cache. To do this, you can use the following command:

pip cache list <pattern>

Note: <pattern> can be a glob expression or a package name.

Step 3 – Is that OK to clear the pip cache?

It is safe to delete the pip cache. However, it is recommended to close all applications to prevent any confusion of the programs accessing the cache. So if you want to free up disk space, you can do it.

Now let’s see how to delete the pip cache package, clean the pip cache, and manually purge the pip cache.

Step 4 – Remove a Package from the pip Cache Safely

To remove a specific package from the pip cache, you can use the following syntax:

pip cache remove <pattern>

For example, you can remove all the files from the cache with the following command:

pip cache remove *         

Step 5 – Clean pip Cache

At this point, if you plan to reset the pip cache to default, you can use the following command:

pip cache purge

Step 6 – Manually purge the pip cache

If you use an older version of pip and have no access to the pip cache command, you can clear the pip cache by manually removing the cache directory. To do this, you can use the command below:

# sudo rm ~/.cache/pip
# sudo rm -rf /root/.cache/pip

Step 7 – How to fix the pip cache unknown command?

At this point, if you want to install a package without looking up the file in the pip cache, you can use the –no-cache-dir option. To do this, you can use the command below:

pip install package_name --no-cache-dir

For more information, you can visit the pip documentation.

Step 8 – What is the difference between purge and remove in the pip cache?

The remove command will remove one or more packages from the cache. The purge command will remove all items from the cache.

Conclusion

At this point, you have learned to manage the pip cache using various commands, and how to clear it in Linux safely. Hope you enjoy it. Please subscribe to us on Facebook and Twitter.

Also, you may be interested in these articles:

Fix Error User Not in Sudoer File on Ubuntu

Change SSH Port on Debian

Check HTTPS Port 443 is Open on Linux

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!