106

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
  • 6,042
  • 1
  • 31
  • 46
Nirav Hathi
  • 1,507
  • 3
  • 12
  • 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
  • 1
    In my case I needed to run: `bundle install` – Dave Aug 17 '22 at 16:19
  • Most of the answers here suggests that cocoapods should be reinstalled in different ways. That might be the issue, but if these solutions doesn't work your problem is probably that the compiler uses the wrong ruby version. Read more here and how to set it right: https://stackoverflow.com/a/71643456/3776782 – turingtested Dec 05 '22 at 13:12
  • Please refer to the latest answer [here](https://stackoverflow.com/questions/73307243/cocoapods-not-found-by-flutter) – Sweta Jain Jun 19 '23 at 05:55

19 Answers19

274

Using following commands, it worked for me.

  1. sudo gem uninstall cocoapods
  2. sudo gem install -n /usr/local/bin cocoapods
  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
Daniel Zolnai
  • 16,487
  • 7
  • 59
  • 71
Aamir
  • 16,329
  • 10
  • 59
  • 65
138

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
  • 18,379
  • 16
  • 47
  • 61
stan liu
  • 1,712
  • 1
  • 11
  • 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
23

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
  • 6,042
  • 1
  • 31
  • 46
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
  • 16,329
  • 10
  • 59
  • 65
Nike Kov
  • 12,630
  • 8
  • 75
  • 122
12

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 are two ways to uninstall 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
  • 2,188
  • 1
  • 31
  • 44
11

Thankfully i found solution after a hour.

As you know, 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,992
  • 1
  • 23
  • 28
7

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
  • 339
  • 4
  • 5
5

Try sudo gem update

  • After remove cocoapods
  • -Install cocoapods
iPC
  • 5,916
  • 3
  • 26
  • 38
4

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,877
  • 3
  • 31
  • 39
3

What finally worked for me was running rvm reset before reinstalling cocoapods

rvm reset
rvm --version
sudo gem install -n /usr/local/bin cocoapods

from here

tonisives
  • 1,962
  • 1
  • 18
  • 17
1

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

Vimal Swaroop J
  • 135
  • 1
  • 10
1

Running these commands worked for me:

  • brew update
  • brew install fastlane
  • fastlane install_plugins
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
1

React native has made several changes and this is how you install pods now

enter image description here

  • cd ios
  • bundle install
  • bundle exec pod install

https://reactnative.dev/docs/environment-setup

Shiza Imtiaz
  • 239
  • 2
  • 3
0

This helped me after I tried all these ways

xcode-select --install
ekkeee
  • 137
  • 11
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
  • 6,413
  • 6
  • 34
  • 57
0

To relink, run:

brew unlink cocoapods && brew link cocoapods
ouflak
  • 2,458
  • 10
  • 44
  • 49
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
0

I have also wrote on github, so I will copy it here, maybe it will be helpful for someone.

To be honest none of those solutions worked for me, just typing randomly commands will not help. I don't know why, but my path was misconfigured. So first you should check if the path is good. I have used brew and installed rbenv in order to use safely libraries and after I ran pod install, I saw it was not targeting the right folder and always used the system version.

After I ran command

gem env

I saw that some paths are not correct. "INSTALLATION DIRECTORY, RUBY EXECUTABLE, EXECUTABLE DIRECTORY, SYSTEM CONFIGURATION DIRECTORY AND GEM PATH" should start something like this(depends of version) /Users/{username}/.rbenv/versions/3.1.2/lib/ruby/. ... otherwise it uses system version.. In order to fix this you need to set paths in ~/.zshrc and ~/.zprofile

my zshrc looks like this:

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH=/opt/homebrew/bin:$PATH
export RBENV_ROOT=$HOME/.rbenv
export PATH=$RBENV_ROOT/shims:/versions:$PATH

zprofile:

eval $(/opt/homebrew/bin/brew shellenv)

in order to change /.zshrc: type nano ~/.zshrc

0

In my opinion if you keep getting these errors for a MacOS in 2023, the best is to try NOT to install the cocoapods using the sudo command "sudo install cocoapods"

rather try installing it from homebrew

if you do not have home-brew on you Mac yet, you can install it using:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

then when all the packages are done installing you can now run the brew installation for cocapods:

brew reinstall cocoapods

Then when this installation is complete, you can try running the flutter doctor command to check for errors (only if you have flutter installed)

flutter doctor