114

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>' 
4
  • 1
    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 Commented Jun 19, 2016 at 7:08
  • 1
    In my case I needed to run: bundle install Commented Aug 17, 2022 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: stackoverflow.com/a/71643456/3776782 Commented Dec 5, 2022 at 13:12
  • Please refer to the latest answer here Commented Jun 19, 2023 at 5:55

21 Answers 21

288

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 
Sign up to request clarification or add additional context in comments.

9 Comments

gem install cocoapods ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/pod I got this error when try to install cocoapods
GEM_NAME_HERE What should this be?
Step 1 and 2: sudo gem install -n /usr/local/bin cocoapods worked for me to install cocoapods.
not one of those command worked for me in 2022. Plus, I'm now getting traceback errors. This actually made things worse.
this approach doesn't work anymore
|
153

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

1 Comment

- Use the $(inherited) flag, or - Remove the build settings from the target. Show this error for my all pods
26

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.

Comments

17

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)

1 Comment

It worked for me too. The second step is pretty much crucial.
16

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

2 Comments

sudo gem update --system was the key for me. After running this it worked for me. Thanks, Milan.
sudo gem update --system broken all my files permissions. Not able to install any other gem package.
15

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 

1 Comment

in the second step, to find which rbenv version I had installed, I had to enter rbenv --version
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.

Comments

6

Try sudo gem update

  • After remove cocoapods
  • -Install cocoapods

2 Comments

gem install cocoapods ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/pod
You should always use sudo gem install instead of gem install
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 

Comments

4

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

Comments

3

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 

Comments

2

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

Comments

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

Comments

1

Running these commands worked for me:

  • brew update
  • brew install fastlane
  • fastlane install_plugins

Comments

0

This helped me after I tried all these ways

xcode-select --install 

Comments

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.

Comments

0

To relink, run:

brew unlink cocoapods && brew link cocoapods 

Comments

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.

1 Comment

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.
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

Comments

0

I got this error when really the problem was that I just needed to re-agree to the Xcode license after updating my os.

I knew this because I ran brew reinstall cocoapods and it told me: Error: You have not agreed to the Xcode license. Please resolve this by running: sudo xcodebuild -license accept

I ran that, and then I didn't get the cocoapods error.

Comments

-1

Make sure your xcode version in 16.0 selected.

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.