Your Search Bar For Shrewd Tips

How Do I Clear Vcpkg Cache?


Clearing the vcpkg cache can free disk space, remove stale build files, or help resolve a package that keeps building incorrectly. The important detail is that vcpkg uses more than one cache: downloaded source archives, temporary build files, installed packages, and optional binary-package archives are stored separately. The right cleanup method depends on which one you want to clear.

This guide explains how to clear each vcpkg cache on Windows, macOS, and Linux, how to find custom cache locations, and what to check before deleting files. In most cases, you can remove one cache without deleting your vcpkg installation or reinstalling every dependency.

What Does the vcpkg Cache Contain?

A typical vcpkg installation has several directories that may be described as “the cache,” even though they serve different purposes:

  • Downloads: Source archives and other files downloaded while installing ports. These are commonly stored in the vcpkg root’s downloads directory.
  • Build trees: Temporary files created while configuring and compiling ports. These are commonly stored in buildtrees.
  • Package staging files: Built package files prepared before installation. These are commonly stored in packages.
  • Installed packages: Libraries and tools available to your project, often under installed. This is your active installation tree, not simply disposable download data.
  • Binary cache: Reusable, prebuilt packages. Depending on your configuration, this may be a local folder, a network share, or a remote service.

Removing one cache does not necessarily clear the others. For example, deleting downloaded source archives does not remove installed libraries, and removing build files does not delete binary packages stored in a separate archive directory.

Find Your vcpkg Cache Locations First

The vcpkg root is the directory containing the vcpkg executable or script and folders such as ports, scripts, and downloads. If you set the VCPKG_ROOT environment variable, it usually points to this directory. Otherwise, use the location where you cloned or installed vcpkg.

Some paths can be changed with environment variables or binary-cache configuration. In particular, VCPKG_DOWNLOADS can point downloads to a different location, and VCPKG_BINARY_SOURCES can define one or more binary-cache sources. Check these settings before deleting files so you clean the cache vcpkg is actually using.

# Linux or macOS
echo "$VCPKG_ROOT"
echo "$VCPKG_DOWNLOADS"
echo "$VCPKG_BINARY_SOURCES"

# PowerShell
$env:VCPKG_ROOT
$env:VCPKG_DOWNLOADS
$env:VCPKG_BINARY_SOURCES

If an environment variable is empty, vcpkg may be using a default or a setting supplied by your build environment. You can also check your project’s CMake toolchain configuration, CI settings, or shell profile for cache paths.

Clear the vcpkg Download Cache

To make vcpkg download source files again the next time it builds a port, remove the contents of the downloads directory. This does not normally uninstall packages already present in installed, but it can increase the time and network traffic required for future builds.

# Linux or macOS: replace the path with your vcpkg root
rm -rf "/path/to/vcpkg/downloads"

# PowerShell: replace the path with your vcpkg root
Remove-Item -Recurse -Force "C:\path\to\vcpkg\downloads"

If VCPKG_DOWNLOADS is set, clear that directory instead of—or in addition to—the default downloads folder. You can remove the directory itself; vcpkg will recreate it when needed. Before running a recursive deletion command, confirm that the path is correct and that it refers only to the cache you intend to remove.

Clear Build Trees and Temporary Package Files

Build trees and staging files are useful targets when a build has failed or you need to reclaim space used by temporary files. vcpkg provides the x-ci-clean command for cleaning its build and package working directories:

vcpkg x-ci-clean

This command is intended for cleaning files from the buildtrees, packages, and installed directories. Because it also removes the installed tree, it can require your project’s packages to be installed again. Check the command’s behavior for your vcpkg version and setup before using it on a working development environment. Do not treat it as a command that only clears temporary build files.

If you only want to remove temporary data and keep installed packages, you can remove the relevant directories from the vcpkg root manually:

# Linux or macOS
rm -rf "/path/to/vcpkg/buildtrees" "/path/to/vcpkg/packages"

# PowerShell
Remove-Item -Recurse -Force "C:\path\to\vcpkg\buildtrees"
Remove-Item -Recurse -Force "C:\path\to\vcpkg\packages"

Use caution with manual cleanup, especially when vcpkg or a build is running. Close active builds first, and avoid deleting the whole vcpkg root. If you want vcpkg to clean temporary files after successful builds in the future, look into the --clean-after-build option supported by the command you use to install packages. This helps limit temporary-file growth, but it does not clear downloads or a separate binary cache.

Clear the Local vcpkg Binary Cache

A binary cache stores built packages so vcpkg can reuse them instead of compiling them again. The default local binary-cache location depends on the operating system, but it can be overridden or replaced by configured sources. Common default locations include:

  • Windows: A vcpkg archives directory under the user’s local application data folder.
  • Linux: An archives directory under the user’s cache directory, commonly ~/.cache/vcpkg/archives.
  • macOS: An archives directory under the user’s library cache directory, commonly ~/Library/Caches/vcpkg/archives.

For a local file-based cache, remove the contents of the configured cache directory. For example, these commands show common paths; check your actual binary-source configuration before using them.

# Linux
rm -rf "$HOME/.cache/vcpkg/archives"

# macOS
rm -rf "$HOME/Library/Caches/vcpkg/archives"

# PowerShell: common Windows location
Remove-Item -Recurse -Force "$env:LOCALAPPDATA\vcpkg\archives"

If your binary cache uses a custom folder, substitute that folder’s path. If it uses a NuGet feed, cloud service, or shared network location, deleting your local files will not clear the remote cache. Remote cached packages must be removed through the storage provider’s tools or settings, if deletion is supported and appropriate.

Clearing a binary cache can make later installs slower because packages may need to be rebuilt or downloaded again. It is usually unnecessary when you only want to fix a broken build; try clearing the affected port’s build files or using a fresh build directory first.

Remove Installed Packages Without Clearing Every Cache

If your goal is to uninstall a library rather than clear cached files, use vcpkg’s package-management commands. For example, removing a package from the installed tree is different from deleting its downloaded source archive or binary archive. The exact command and options depend on whether you use classic mode or manifest mode.

In manifest mode, dependencies are typically installed based on the project’s vcpkg.json file. Removing a package from that manifest and reinstalling or updating the project’s dependencies is generally more appropriate than manually deleting files from the installed tree. In classic mode, use the relevant vcpkg remove options for the package and installation you intend to change.

Do not delete the installed directory if you want to preserve the packages currently available to your project. Cleaning it can lead to missing-library errors until the dependencies are installed again.

Which vcpkg Cache Should You Clear?

  • Need more disk space? Check the sizes of downloads, buildtrees, packages, and the configured binary cache. Remove only what you do not need.
  • A port repeatedly fails to build? Close active builds, then consider removing that port’s temporary build files or rebuilding with a clean build directory. Avoid clearing every cache as a first step.
  • Want fresh source downloads? Clear the downloads directory, including any custom VCPKG_DOWNLOADS location.
  • Want vcpkg to compile packages instead of reusing prebuilt ones? Clear or adjust the relevant binary-cache source. Remember that the cache may be remote.
  • Want to uninstall a dependency? Use the package-management workflow for your vcpkg mode instead of deleting cache files.

Common Mistakes to Avoid

Do not assume that every directory named packages or installed is safe to erase. The installed tree contains files your project may be using, while removing build and download caches can cause longer rebuilds or additional network requests. Also, do not run recursive deletion commands with a blank or unchecked path; verify the target directory before pressing Enter.

Another common mistake is clearing only the default location when vcpkg is configured to use a custom one. If clearing a cache does not change the behavior you see, inspect VCPKG_DOWNLOADS, VCPKG_BINARY_SOURCES, project configuration, and CI variables. The active cache may be somewhere else or may be remote.

Conclusion

To clear the vcpkg cache, first identify which cache you mean. Remove downloads to discard downloaded source files, clean buildtrees and packages to remove temporary build data, or clear the configured binary-cache location to discard reusable prebuilt packages. Use vcpkg x-ci-clean with care because it can also remove installed files, and use package commands—not cache deletion—to uninstall dependencies. Verify every path before deleting it, and remember that vcpkg will recreate needed cache data during a future build.


Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.

Shrewdnia

Shrewdnia

Shrewdnia is a destination for curious minds seeking clarity, knowledge, and informed perspectives. Through insightful articles and practical guides our passionate team explores a wide range of topics designed to help readers understand the world around them, make smarter decisions, and stay informed in an ever-changing landscape.


💡 Every question sparks discovery, and every perspective enriches the conversation. Share your thoughts and insights in the comments 👇

Back to blog

Leave a comment

JOIN THE SHREWDNIA COMMUNITY FORUM

What do you think?

Have an opinion, experience, or question about this topic? Join the Shrewdnia Forum and share your thoughts with other readers.

Join the Forum →