未安装 cocoapods

这意味着什么? 我该如何解决这个问题:

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>'
138806 次浏览

Try sudo gem update

  • After remove cocoapods
  • -Install cocoapods

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

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.

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

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)

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

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.

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

This helped me after I tried all these ways

xcode-select --install

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

Running these commands worked for me:

  • brew update
  • brew install fastlane
  • fastlane install_plugins

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.

To relink, run:

brew unlink cocoapods && brew link cocoapods

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.

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

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

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

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