How to Clear a Specific Pod from the CocoaPods Cache

How to Clear a Specific Pod from the CocoaPods Cache

Written by

in

Quick answer: Run pod cache clean '<PodName>' --all in Terminal to purge all cached versions of a single pod. If you only want to remove a specific build, run pod cache clean '<PodName>' and select the entry interactively from the numbered list.

Why this happens

CocoaPods stores downloaded podspecs, remote tarballs, and Git repositories in a global cache directory located at ~/Library/Caches/CocoaPods/. When you execute pod install or pod update, CocoaPods checks this cache before making network requests. If a matching pod name and version already exist locally, CocoaPods copies the cached source directly into your project’s Pods/ directory.

This caching mechanism breaks down when dependency maintainers update code without incrementing the release version, or when you depend on an external Git branch such as :branch => 'main'. In these cases, CocoaPods may keep using outdated, locally cached revisions. Even if you remove the pod from your Podfile, run pod install, and re-add it, CocoaPods re-extracts the stale version from disk.

Developers frequently resort to wiping the entire cache directory (rm -rf ~/Library/Caches/CocoaPods). While that resolves the issue, it forces CocoaPods to re-download every single dependency across all your projects during the next install. Clearing only the offending pod saves significant bandwidth and build time.

How to fix it

1. View the cached entries for the pod

Before deleting anything, inspect the exact versions and disk locations CocoaPods has indexed for the pod. Run pod cache list in Terminal:

pod cache list

To narrow the output to a specific pod, pipe the result into grep or search for the library name:

pod cache list | grep -A 10 'YourPodName'

The output displays whether the pod is a published release or an external reference, alongside the file paths inside your local cache:

YourPodName:
  - Version: 1.4.2
    Type:    Release
    Spec:    /Users/developer/Library/Caches/CocoaPods/Pods/Specs/Release/YourPodName/1.4.2.podspec.json
    Pod:     /Users/developer/Library/Caches/CocoaPods/Pods/Release/YourPodName/1.4.2-ab12cd
  - Version: 1.4.2
    Type:    External
    Spec:    /Users/developer/Library/Caches/CocoaPods/Pods/Specs/External/YourPodName/hash.podspec.json
    Pod:     /Users/developer/Library/Caches/CocoaPods/Pods/External/YourPodName/hash

2. Remove all cached versions of the pod

To purge all cached versions of a specific dependency at once, use the clean subcommand with the --all flag:

pod cache clean 'YourPodName' --all

Terminal will confirm the deletion:

[!] Removed 2 cached pods.

This removes all spec metadata and source files for that single library without disturbing your other project dependencies.

3. Interactively remove a single cached version

If you maintain multiple projects that rely on older versions of the same library and you only want to clear a problematic snapshot or Git commit, omit the --all flag:

pod cache clean 'YourPodName'

CocoaPods will print a numbered menu of all cached instances for that pod:

1: YourPodName v1.4.2 (Release)
2: YourPodName v1.4.2 (External)
3: YourPodName v1.5.0 (Release)

Which pod cache do you want to remove? [1-3] or 'all'

Type the number corresponding to the stale version and press Enter. CocoaPods will delete only that specific entry.

4. Delete the local project reference and reinstall

Clearing the global cache does not alter the copy currently checked out inside your project. You must remove the local reference and the lockfile entry before re-fetching the pod:

# Navigate to your project directory
cd /path/to/YourProject

# Remove the local copy of the pod
rm -rf Pods/YourPodName

# Remove Podfile.lock to allow resolution
rm Podfile.lock

# Fetch the updated pod
pod install --repo-update

If you prefer not to discard the entire Podfile.lock because you have other pinned dependencies you do not want to alter, update only that specific pod:

pod update YourPodName

5. Manually remove corrupted external pod specs

In rare instances where a Git checkout in the cache was interrupted or contains broken symbolic links, pod cache clean may report that the pod was removed even though corrupted files remain on disk. You can delete them manually:

# For release-based pods
rm -rf ~/Library/Caches/CocoaPods/Pods/Release/YourPodName
rm -rf ~/Library/Caches/CocoaPods/Pods/Specs/Release/YourPodName

# For Git-based or external pods
rm -rf ~/Library/Caches/CocoaPods/Pods/External/YourPodName
rm -rf ~/Library/Caches/CocoaPods/Pods/Specs/External/YourPodName

After removing these directories, run pod install again to trigger a fresh download.

How to prevent it

  • Pin exact Git commits instead of branches: In your Podfile, use :commit => 'abc1234' rather than :branch => 'main'. Commit hashes prevent CocoaPods from reusing an older cached state when remote branches receive new commits.
  • Enforce semantic versioning: Avoid republishing modified code under an identical version tag. When authoring private pods, always increment the version number in the .podspec file.
  • Use targeted updates: Run pod update <PodName> instead of a global pod update to refresh individual dependencies without altering locked versions of other libraries.
  • Avoid hardcoding repository URLs without tags: Pointing a pod directly to a Git URL without a tag or commit makes cache invalidation unpredictable across continuous integration and developer machines.

FAQ

Will clearing a specific pod cache affect other team members?

No. The CocoaPods cache is stored locally on your Mac under ~/Library/Caches/CocoaPods/. Clearing it only affects your local machine and forces your system to re-download the dependency.

What is the difference between pod cache clean and pod deintegrate?

pod cache clean deletes downloaded library files and podspecs from your machine’s global cache directory. pod deintegrate removes CocoaPods references, build phases, and linked .xcconfig files from your Xcode project file (.xcodeproj).

Why does CocoaPods still install an old commit after clearing the cache?

Check your Podfile.lock. If you run pod install instead of pod update <PodName>, CocoaPods honors the exact commit or version already recorded in Podfile.lock, regardless of what is available remotely or in your cache.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.