134

How to delete or clear a specific pod from cocoapods cache?

Tried deleting the entire cache directly, it takes lot of time to get back all pods. How to view and remove specific pod from cache?

Following works (longer time commit):

# delete all cached pods
`rm -rf "${HOME}/Library/Caches/CocoaPods"`  

# delete local Pods/*
rm -rf "`pwd`/Pods/"

# pod update to fetch latest. After entire cache deletion, it takes lot longer to fetch and rebuild pod cache from scratch. 
`pod update` 

Just commenting out from podfile, and pod install again fetches old version from cache.

Having many instances of same pod in the pod cache can be troublesome when the pod is large, one of the pod currently in use has size of >1.5 GB in a project that is using cocoapods1.3.1 with Xcode9.

2
  • Just delete it from your pod file and update. What are you trying to do exactly?
    – Desdenova
    Sep 26, 2017 at 14:18
  • @Desdenova, just deleting from podfile and pod update doesn't clear it from the cache.
    – lal
    Sep 26, 2017 at 14:32

2 Answers 2

321

Clearing a specific pod

pod cache clean --all # will clean all pods
pod cache clean 'FortifySec' --all # will remove all installed 'FortifySec' pods 

Sample output of pod cache clean 'FortifySec', for pods not using semantic versioning, this could result in many copies of same pod in cache:

pod cache clean 'FortifySec'
1: FortifySec v2.2 (External)
2: FortifySec v2.2 (External)
...
...
18: FortifySec v2.2 (External)
19: FortifySec v2.2 (External)

Which pod cache do you want to remove?

Complete cleanup (pod reset)

rm -rf ~/Library/Caches/CocoaPods
rm -rf Pods
rm -rf ~/Library/Developer/Xcode/DerivedData/*
pod deintegrate
pod setup
pod install

Example of pod cache list prior to clean

pod cache list

FortifySec:
- Version: 2.2.1
Type:    External
Spec:    /Users/j.d/Library/Caches/CocoaPods/Pods/Specs/External/FortifySec/ui99sd....podspec.json
Pod:     /Users/j.d/Library/Caches/CocoaPods/Pods/External/FortifySec/yi23sd...-sdjc3
- Version: 2.2.1
Type:    External
Spec:    /Users/j.d/Library/Caches/CocoaPods/Pods/Specs/External/FortifySec/dsfs-df23
Pod:     /Users/j.d/Library/Caches/CocoaPods/Pods/External/FortifySec/dfs0d-2dfs
- Version: 2.2
Type:    External
Spec:    /Users/j.d/Library/Caches/CocoaPods/Pods/Specs/External/FortifySec/u78hyt....podspec.json
Pod:     /Users/j.d/Library/Caches/CocoaPods/Pods/External/FortifySec/e000sd
- Version: 2.2.2
Type:    External
Spec:    /Users/j.d/Library/Caches/CocoaPods/Pods/Specs/External/FortifySec/s2d-df.podspec.json
Pod:     /Users/j.d/Library/Caches/CocoaPods/Pods/External/FortifySec/ds34sd....
- Version: 2.2.1
Type:    External
Spec:    /Users/j.d/Library/Caches/CocoaPods/Pods/Specs/External/FortifySec/sdfsdfdsf....podspec.json
Pod:     /Users/j.d/Library/Caches/CocoaPods/Pods/External/FortifySec/edfs5d7...
AFNetworking:
- Version: 2.5.3
Type:    Release
Spec:    /Users/j.d/Library/Caches/CocoaPods/Pods/Specs/Release/AFNetworking/2.6.podspec.json
Pod:     /Users/j.d/Library/Caches/CocoaPods/Pods/Release/AFNetworking/2.6.3-4e7e2

Notice the multiple pod cache for - Version: 2.2.1. It's a good idea to do so to get rid of unnecessary disk space used by pod cache.

4
  • 1
    it's actually rm -rf Pods does the work that I needed
    – Tony Lin
    Nov 6, 2018 at 6:07
  • @TonyLin rm -rf Pods only deletes it from the local project directly. Upon pod install, cocoapods first pulls the pod from the local cache in ../Library/Cache/CocoaPods/...
    – lal
    Jan 30, 2020 at 22:48
  • ~/Library/Caches/CocoaPods helps me, I'd just want to clean private spec cache, and re-download it.
    – Leo
    Nov 20, 2020 at 14:11
  • I comment this line in Podfile and it works for me. # platform :ios, '10.0'
    – Johnny
    Nov 24, 2022 at 8:42
1

Safe steps with explanation, no pods deintegration included and React Native friendly.

  1. Delete Derivate Data - Remove data that includes cached info of the project Example how to do it: https://www.youtube.com/watch?v=f8bTvx0Aoyo

  2. Remove the .xcworkspace file from iOS folder - This is the Xcode project file that gets created when you run pod install we want to recreate it in step 4. This project file uses pods and has a white coloured icon instead of the blue coloured base project without pods.

  3. Remove Podfile.lock - Remove old dependencies info so we can recreate them in the next step.

  4. Do a pod-install in iOS folder or npx pod-install in root with (React native) - Here we download the pod dependencies again and the pod files only the ones that are used from the latest package-lock are downloaded and integrated so removed package pods from package.json are gone. A .xcworkspace is regenerated.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.