91

What does it mean and how can I fix it:

pod install
/Library/Ruby/Site/2.0.0/rubygems.rb:250:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) (Gem::GemNotFoundException)
from /Library/Ruby/Site/2.0.0/rubygems.rb:278:in `activate_bin_path'
from /usr/local/bin/pod:22:in `<main>'
x4h1d
  • 5,957
  • 1
  • 30
  • 44
Nirav Hathi
  • 1,337
  • 2
  • 11
  • 20
  • 1
    https://cocoapods.org/app download cocoapods app from this link, then open your podfile using the app and click on install then update and finally open workspace file – Meet Jun 19 '16 at 07:08

15 Answers15

237

Using following commands, it worked for me.

  1. sudo gem uninstall cocoapods
  2. sudo gem install -n /usr/local/bin
  3. cocoapods pod install

If you encounter this error on step 2:

ERROR: While executing gem ... (Gem::CommandLineError) Please specify at least one gem name (e.g. gem build GEMNAME)

Then try this as step 2 instead (step 3 is not needed):

gem install -n /usr/local/bin cocoapods
mattias
  • 1,098
  • 12
  • 25
Aamir
  • 15,011
  • 10
  • 55
  • 64
108

If you install cocoapod using brew like me

  1. Reinstall cocoapods:

    brew reinstall cocoapods
    

If you see this error message after you reinstall cocoapods by brew reinstall go to step 2.

>
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/pod
Target /usr/local/bin/pod
already exists. You may want to remove it:
  rm '/usr/local/bin/pod'

To force the link and overwrite all conflicting files:
  brew link --overwrite cocoapods

To list all files that would be deleted:
  brew link --overwrite --dry-run cocoapods

Possible conflicting files are:
/usr/local/bin/pod
/usr/local/bin/xcodeproj
  1. To solve conflicting files:

    brew link --overwrite cocoapods
    

    Linking /usr/local/Cellar/cocoapods/1.3.1... 2 symlinks created

Tomerikoo
  • 15,737
  • 15
  • 35
  • 52
stan liu
  • 1,412
  • 1
  • 10
  • 14
  • - Use the `$(inherited)` flag, or - Remove the build settings from the target. Show this error for my all pods – Chandni Feb 23 '18 at 11:26
  • 1
    UPVOTED!. This is the only solution has worked for me. I was stuck on and wouldn't be able to use or download any pods inside my projects for TWO days. Many Thanks. My problem was that I get this error message frequently : ERROR: Failed to build gem native extension. – Mohammed Hasan May 09 '20 at 20:53
  • 1
    Thank you, man. You saved me. I uninstalled cocoapods while using Big Sur Beta and for the life of me I was unable to install it again. – rmvz3 Sep 22 '20 at 21:25
  • THANK YOU!!!!!!!!! – Bruce Bruce Jan 10 '22 at 16:13
19

Uninstall the existing cocoapods, if any, by following command:

gem list --local | grep cocoapods | awk '{print $1}' | xargs sudo gem uninstall

Then install it to /usr/local/bin instead of /usr/bin using following command:

sudo gem install -n /usr/local/bin cocoapods

For further query, check this link to uninstall and this link to install cocoapods.

Community
  • 1
  • 1
x4h1d
  • 5,957
  • 1
  • 30
  • 44
16

In my case nothing helped, then I:

  1. sudo gem uninstall cocoapods
  2. cd /Users/nikkov/.rvm/rubies/ruby-2.4.1/lib/ruby; In Finder I searched for cocoapods and removed everything.
  3. brew install cocoapods
  4. brew link --overwrite cocoapods (if needed)
Aamir
  • 15,011
  • 10
  • 55
  • 64
Nike Kov
  • 11,754
  • 6
  • 65
  • 104
10

I had upgraded my ruby version 2.5.3 to 2.7.2. Then, I want to update cocoapods from 1.9.3 to 1.10.0 . I got the following error while executing pod install.

can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)

There is two way to install cocoapods by using homebrew & gem. If you had install cocoapods using gem run following.

sudo gem uninstall cocoapods
sudo gem uninstall -n /usr/local/bin cocoapods

If you had used brew please using the following to uninstall

brew uninstall cocoapods

If you forgot which one you used earlier, please execute both commands. Please make sure all cocoapods instances are removed to check run pod --version.

If you find -bash: pod: command not found as output, all instances are removed properly. Else, you may need to remove cocoapods related files manually from this directory ~/.rvm/rubies/ruby-2.5.3/lib/ruby.

sudo gem update --system
gem install cocoapods

CREDIT: https://blog.csdn.net/develop_csdn/article/details/105053383

Milan Kamilya
  • 1,930
  • 29
  • 42
5

Try sudo gem update

  • After remove cocoapods
  • -Install cocoapods
iPC
  • 5,524
  • 3
  • 24
  • 36
4

In my case the reason of the issue was Gemfile file inside the folder with the project. When I removed this file, cocoapods started functioning as usual.

Terry
  • 309
  • 3
  • 5
3

When I tried @Aamir's solution, I ran into the error:

ERROR: Could not find a valid gem 'cocoapods' (>= 0), here is why: Unable to download data from https://rubygems.org/ - no such name (https://api.rubygems.org/specs.4.8.gz)

This worked for my Mac:

sudo gem uninstall cocoapods
sudo gem install cocoapods
Ryan Loggerythm
  • 2,309
  • 1
  • 27
  • 37
2

Thankfully i found solution after a hours.

As you now, newest Mac Operation System(Big Sur or oldest one) use ruby as a version system. So this ruby is private. You can not write/update some files that belong ruby.

So, we had a change to install rbenv for as a version control.

Firstly you should install rbenv via brew if you don't have

$ brew install rbenv

You need to know rbenv version number. You can see with below code snipped

$ rbenv version

Install Xcode's command line tools

xcode-select --install

Install rbenv via Homebrew

brew update
brew install rbenv ruby-build

Configure rbenv

eval "$(rbenv init -)"

Install and configure Ruby

rbenv install 3.1.1
rbenv global 3.1.1
rbenv rehash
source ~/.bash_profile

Install Cocoapods:

gem install cocoapods
Emre Gürses
  • 1,710
  • 19
  • 25
1

Running these commands worked for me:

  • brew update
  • brew install fastlane
  • fastlane install_plugins
Tomerikoo
  • 15,737
  • 15
  • 35
  • 52
0

This helped me after I tried all these ways

xcode-select --install
ekkeee
  • 133
  • 9
0

Try changing command line tools

In my case I was not able to install pod and cocoapods using gem, after changing command line tools I was able to run the commands

0

If anyone stumbles upon this as a result of updating to react native 0.67.2+ from an older version (we were on 0.66.0) you have to make sure you re-install cocoapods via gem install cocoapods. Otherwise, your pod install will not work.

Simon
  • 5,903
  • 6
  • 30
  • 54
0

To relink, run:

brew unlink cocoapods && brew link cocoapods
ouflak
  • 2,408
  • 10
  • 40
  • 47
0

I'd installed Cocoapods using gem, so I reinstalled it again using gem. nothing happened. so I removed it and install it using brew. it works.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 07 '22 at 11:24