pod install cannot set up the trunk spec source from cdn.cocoapods.org
Your error
Unable to add a source with url `https://cdn.cocoapods.org/` named `trunk`.1 more line it can showFix it fast
Most common cause, 1 of 2The CDN cannot be reached from this machine
Make the CDN reachable from that shell: export the proxy under the https name, or run on a network that allows cdn.cocoapods.org.
export https_proxy=http://proxy.example.com:8080
pod installShort answer
Unable to add a source with url `https://cdn.cocoapods.org/` named `trunk` means CocoaPods tried to create its trunk spec source and failed. The reason is hidden unless you add --verbose: either the CDN could not be reached, for example through a proxy that is not set, or the repos folder under ~/.cocoapods could not be written. CocoaPods 1.16 to 1.17.
Which cause do you have?
Run the install again with --verbose. Only then does CocoaPods print, in parentheses on the line below the first one, the error that made adding the source fail.
pod install --verbose 2>&1 | grep -A3 "Unable to add a source"Then find the line you see in this list and open its fix:
- 1The CDN cannot be reached from this machine
The verbose line reads CDN: trunk URL couldn't be downloaded: https://cdn.cocoapods.org/CocoaPods-version.yml Response: followed by a network message - 2The repos folder cannot be created or written
The verbose line reads Could not create '/Users/me/.cocoapods/repos', the CocoaPods repo cache directory, with an Errno::EACCES or similar error
What does the error look like?
Unable to add a source with url `https://cdn.cocoapods.org/` named `trunk`.You can try adding it manually in `/Users/me/.cocoapods/repos` or via `pod repo add`.
Cause 1 of 2
The CDN cannot be reached from this machine
You seeThe verbose line reads CDN: trunk URL couldn't be downloaded: https://cdn.cocoapods.org/CocoaPods-version.yml Response: followed by a network message
Check
To add trunk, CocoaPods first downloads CocoaPods-version.yml from the CDN. When that download keeps failing after its retries, adding the source fails and the outer message is all you see. CocoaPods downloads with Typhoeus, a Ruby client built on libcurl, and libcurl takes its proxy from the environment variable named after the URL scheme, so behind a proxy the https_proxy variable has to be set in the shell that runs pod.
curl -sS https://cdn.cocoapods.org/CocoaPods-version.yml
env | grep -i _proxyFix
Make the CDN reachable from that shell: export the proxy under the https name, or run on a network that allows cdn.cocoapods.org. Then install again.
export https_proxy=http://proxy.example.com:8080
pod installVerify
curl prints the version file (lines starting with min: and last:), and pod repo list shows a trunk entry.
curl -sS https://cdn.cocoapods.org/CocoaPods-version.yml
pod repo listConfirmed by raw.githubusercontent.com
Cause 2 of 2
The repos folder cannot be created or written
You seeThe verbose line reads Could not create '/Users/me/.cocoapods/repos', the CocoaPods repo cache directory, with an Errno::EACCES or similar error
Check
Before it downloads anything, CocoaPods makes a folder for the new source under the repos directory and writes the source URL into it. The repos directory is ~/.cocoapods/repos unless CP_HOME_DIR or CP_REPOS_DIR points elsewhere. If an earlier sudo pod run left ~/.cocoapods owned by root, or the variable points at a read-only CI cache path, that first write fails.
ls -ld ~/.cocoapods ~/.cocoapods/repos
env | grep -E "CP_(HOME|REPOS)_DIR"Fix
Give the folder back to your user, or point the variable at a writable path, then install again without sudo.
sudo chown -R "$USER" ~/.cocoapods
pod installVerify
The trunk folder now exists under the repos directory, with a .url file holding the CDN address.
cat ~/.cocoapods/repos/trunk/.urlConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Set https_proxy in the CI environment of every iOS job that runs behind a proxy, next to the other proxy variables.
- Never run pod with sudo, so nothing under ~/.cocoapods ends up owned by root.
- When a CI job sets CP_HOME_DIR or CP_REPOS_DIR to a cache path, check that the job user can write to it.
Sources
- CocoaPods source: Unable to add a source message (sources_manager.rb, 1.17.0)
- CocoaPods source: repo add-cdn command (add_cdn.rb, 1.17.0)
- CocoaPods Core source: CDN downloads and retries (cdn_source.rb)
- CocoaPods source: repos directory and CP_HOME_DIR (config.rb)
- libcurl: CURLOPT_PROXY and proxy environment variables
- Typhoeus: Ruby HTTP client built on libcurl
- CocoaPods guides: command-line reference (pod repo add-cdn)
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.