:tag => s.version.to_s to the source hash and use HTTPS URLs. If the issue persists, reset the CocoaPods master repo with pod repo remove master && pod setup.Why this happens
CocoaPods resolves dependencies by matching the version declared in a podspec (e.g., s.version = "1.0.0") to a git tag in the source repository. When you specify a source like:
s.source = { :git => "git@github.com:myrepo/Podspecs.git", :branch => "xyz" }
CocoaPods clones the repository at the given branch but cannot locate a tag named 1.0.0. Without that tag, it cannot verify that the code at that version matches the podspec, so it aborts with:
[!] Unable to find a specification for ABC (= 1.0.0)
Two common causes compound the problem:
- Missing version tag – The podspec declares a version but the source hash omits
:tag => s.version.to_s. CocoaPods expects a tag that exactly equals the version string. - SSH git URLs – Using
git@github.com:...requires SSH keys to be present on the machine runningpod install. In CI environments or on machines without the correct keys, the clone fails silently, leading to the same error.
How to fix it
1. Add the version tag to the podspec source (most likely fix)
Edit the podspec for the missing dependency (in this example, ABC.podspec). Change the source hash to include the tag and switch to an HTTPS URL:
Pod::Spec.new do |s|
s.name = "ABC"
s.version = "1.0.0"
s.source = { :git => "https://github.com/myrepo/Podspecs.git",
:branch => "xyz",
:tag => s.version.to_s }
end
Key points:
– :tag => s.version.to_s expands to "1.0.0" and tells CocoaPods to check out that exact tag.
– https:// works without SSH keys and is safe for public and private repos (provided credentials are configured via GitHub tokens or .netrc).
– Keep :branch if the tag lives on a non-default branch; CocoaPods will fetch the tag from that branch.
After updating the podspec, push the tag to the remote:
git tag 1.0.0
git push origin 1.0.0
Then run pod install again.
2. Reset the CocoaPods master spec repo
If the podspec is correct but CocoaPods still cannot find the specification, the local copy of the master spec repo may be stale or corrupted. Reset it:
pod repo remove master
pod setup
pod install
Or, if you prefer the manual method:
rm -rf ~/.cocoapods/repos/master
pod setup
pod install
This re-clones the canonical CocoaPods spec repository, ensuring all public pod specifications are up to date.
3. Validate the podspec with pod spec lint
Before publishing or depending on a private podspec, run the linter to catch missing tags, incorrect source URLs, and other issues:
pod spec lint ABC.podspec --verbose
For a private spec repo, include the repo URL:
pod spec lint ABC.podspec --sources='https://github.com/myorg/PrivateSpecs.git,https://cdn.cocoapods.org/'
Fix any errors or warnings before pushing the tag.
How to prevent it
- Tag every release – Create a git tag that matches
s.versionexactly (e.g.,1.0.0, notv1.0.0) before publishing. - Use HTTPS source URLs – Avoid
git@SSH URLs in podspecs; they break in automated environments. - Lint before push – Run
pod spec linton every podspec change. - Keep spec repos updated – Run
pod repo updateperiodically, especially beforepod installin CI. - Declare private spec repos in the Podfile – Add
source 'https://github.com/myorg/PrivateSpecs.git'at the top of the Podfile so CocoaPods knows where to look.
FAQ
Why does CocoaPods require a git tag that matches the version?
CocoaPods uses the tag to guarantee that the source code retrieved for a given version is immutable and reproducible. Without a tag, the same version could point to different commits over time.
Can I use a branch name instead of a tag?
No. CocoaPods does not support branch-based version resolution for dependencies declared with an exact version (= 1.0.0). You must provide a tag. For development pods you can use :path or :branch in the Podfile, but not in a published podspec.
What if my private repo uses SSH and I cannot switch to HTTPS?
Configure SSH keys for the user running pod install (including CI runners). Add the private key to the keychain or use ssh-agent. However, HTTPS with a personal access token is simpler and more portable.
Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.
