gem install cocoapods gets no gem from rubygems.org
Your error
ERROR: Could not find a valid gem 'cocoapods' (>= 0) in any repository2 more lines it can showFix it fast
Most common cause, 1 of 3rubygems.org cannot be reached, or the proxy sits under a name RubyGems ignores
Export the proxy under the https name in the same shell, or hand it to gem with --http-proxy, which takes priority over the environment.
export https_proxy=http://proxy.example.com:8080
gem install cocoapods
# or for one command only
gem install cocoapods --http-proxy http://proxy.example.com:8080Short answer
gem install cocoapods prints Could not find a valid gem 'cocoapods' (>= 0) when RubyGems got no usable reply from its sources. A following 'here is why' line names a network, proxy or server error from rubygems.org; without that line, the source list lacks rubygems.org. Export https_proxy, retry a 5xx later, or add https://rubygems.org/. RubyGems 3.5 to 4.1.
Which cause do you have?
Run the install once more and keep its last lines, then print the gem sources and any proxy variables. A 'here is why' line means cause 1 or 2 below; a bare 'in any repository' ending means cause 3.
gem install cocoapods 2>&1 | tail -n 4
gem sources --list
env | grep -i _proxyThen find the line you see in this list and open its fix:
- 1rubygems.org cannot be reached, or the proxy sits under a name RubyGems ignores
here is why: Unable to download data from https://rubygems.org/ - followed by a connection, name lookup or timeout message - 2The server answered with an HTTP error such as 503
The here is why line contains bad response (Bad response in RubyGems 4.1), a reason such as Backend read error and a 5xx status code - 3The gem source list has no rubygems.org entry
The message ends with in any repository and no here is why line, and gem sources --list does not show https://rubygems.org/
What does the error look like?
ERROR: Could not find a valid gem 'cocoapods' (>= 0) in any repositoryERROR: Could not find a valid gem 'cocoapods' (>= 0), here is why:Unable to download data from https://rubygems.org/ - bad response Backend read error 503
Cause 1 of 3
rubygems.org cannot be reached, or the proxy sits under a name RubyGems ignores
You seehere is why: Unable to download data from https://rubygems.org/ - followed by a connection, name lookup or timeout message
Check
When Could not find a valid gem 'cocoapods' carries a here is why line, RubyGems could not download data from the source, so it never saw the cocoapods entry. On a network that needs a proxy, note how RubyGems picks one: for an https source it reads only https_proxy or HTTPS_PROXY, and if neither is set it connects directly, so a lone HTTP_PROXY export changes nothing.
env | grep -i _proxy
curl -sI https://rubygems.org/ | head -n 1Fix
Export the proxy under the https name in the same shell, or hand it to gem with --http-proxy, which takes priority over the environment. Then install again.
export https_proxy=http://proxy.example.com:8080
gem install cocoapods
# or for one command only
gem install cocoapods --http-proxy http://proxy.example.com:8080Verify
gem reports how many gems it installed, and pod answers with its version.
pod --versionConfirmed by raw.githubusercontent.com
Cause 2 of 3
The server answered with an HTTP error such as 503
You seeThe here is why line contains bad response (Bad response in RubyGems 4.1), a reason such as Backend read error and a 5xx status code
Check
Here the request reached a server, but the reply was an error. RubyGems copies the reason text and the status code into the message. RFC 9110 defines 503 Service Unavailable as a temporary overload or maintenance that will likely clear after some delay, so nothing on the Mac needs repair. When it only ever appears on one office or CI network, the proxy or mirror on that network is the server that answers.
curl -sI https://rubygems.org/ | head -n 1Fix
Wait a few minutes and run the same install. If the error stays on one network while rubygems.org loads fine elsewhere, take it to whoever runs that proxy or mirror.
gem install cocoapodsVerify
curl prints a 200 status line, and the install ends with a count of installed gems.
curl -sI https://rubygems.org/ | head -n 1Confirmed by raw.githubusercontent.com
Cause 3 of 3
The gem source list has no rubygems.org entry
You seeThe message ends with in any repository and no here is why line, and gem sources --list does not show https://rubygems.org/
Check
With no fetch error recorded, every listed source replied, yet none of them offers cocoapods. That is what a list holding only a private gem server, a dead mirror or an old entry looks like. The gem sources help names https://rubygems.org as the recommended source and says to remove sources you do not recognize.
gem sources --listFix
Add the official source and remove the entry that should not be there, then install.
gem sources --add https://rubygems.org/
gem sources --remove https://gems.old-mirror.example.com/
gem install cocoapodsVerify
The list shows https://rubygems.org/, and pod runs.
gem sources --list
pod --versionConfirmed by guides.rubygems.org
How do I stop it coming back?
- On machines behind a proxy, set https_proxy in the shell profile and in the CI environment, not only HTTP_PROXY.
- Check gem sources --list when you set up a new Mac or build image, and keep only rubygems.org plus private servers you really use.
- Pin CocoaPods in the project's Gemfile, as the CocoaPods guide suggests, so a retry installs the same version everywhere.
Sources
- RubyGems source: proxy lookup from the environment (request.rb, v4.1.0)
- RubyGems source: Could not find a valid gem message (command.rb, v4.1.0)
- RubyGems source: bad response errors (remote_fetcher.rb, v4.1.0)
- RubyGems guides: command reference (gem sources, gem install)
- RFC 9110: 503 Service Unavailable
- CocoaPods guides: getting started
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.