17

using zsh - use to work in bash
brew doctor - Your system is ready to brew.
flutter doctor gives this error

[!] Xcode - develop for iOS and macOS (Xcode 12.2)
    ✗ CocoaPods installed but not working.
        You appear to have CocoaPods installed but it is not working.
        This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it.
        This can usually be fixed by re-installing CocoaPods. For more info, see https://github.com/flutter/flutter/issues/14293.
      To re-install CocoaPods, run:
        sudo gem install cocoapods  

sudo gem install cocoapods

Gives this error  
dyld: Library not loaded: /usr/local/opt/gmp4/lib/libgmp.3.5.2.dylib  
  Referenced from: /Users/puser/.rvm/rubies/ruby-2.5.1/bin/ruby  
  Reason: image not found  
zsh: abort      sudo gem install cocoapods  

I can't get this error above corrected - any suggestions?

which pod

/Users/puser/.rvm/rubies/ruby-2.5.1/bin/pod

which gem

gem () {
    \typeset result
    (
        \typeset rvmrc
        rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc") 
        if [[ -n "${rvm_prefix:-}" ]] && ! [[ "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]]
        then
            rvm_rvmrc_files+=("${rvm_prefix}/.rvmrc") 
        fi
        for rvmrc in "${rvm_rvmrc_files[@]}"
        do
            [[ -s "${rvmrc}" ]] && source "${rvmrc}" || true
        done
        unset rvm_rvmrc_files
        command gem "$@"
    ) || result=$? 
    hash -r
    return ${result:-0}
}

which ruby

/Users/puser/.rvm/rubies/ruby-2.5.1/bin/ruby
Mathias
  • 4,243
  • 4
  • 25
  • 34

11 Answers11

51

Using the suggestion for this post, I was able to get cocoapods reinstalled with the commands below
gem native extension error while installing cocoapods

Open Terminal

curl -L https://get.rvm.io | bash -s stable

Reopen Terminal

rvm install ruby-2.6

rvm use ruby-2.6.5

rvm --default use 2.6.5

Then this installed cocoapods as expected

sudo gem install cocoapods
Mathias
  • 4,243
  • 4
  • 25
  • 34
  • 1
    Thanks. It helps me a lot. – anticafe Mar 31 '21 at 15:00
  • 4
    Thanks. you save me! I wanna give you additional information. If you are using Flutter on m1. then you should install it like this. `rvm install ruby-2.6 --with-out-ext=fiddle` In my case, the installed version is 2.6.6. so maybe you change this specific version. – Seong Jun Jul 12 '21 at 11:01
  • 1
    Cheers!! After hours this finally worked. – Adeolaex Aug 04 '21 at 14:32
  • 7
    Thanks. The rvm website recommended to download using `\curl -sSL https://get.rvm.io | bash -s stable` and then I installed `rvm install ruby-2.7.2` Make sure you do not have CocoaPods installed using Homebrew and if so, `brew uninstall cocoapods`. Then, `rvm --default use 2.7.2` and `sudo gem install cocoapods` worked for me – biniam Sep 22 '21 at 15:45
  • 1
    Thanks a lot... it's working for me – urmish patel Feb 16 '22 at 11:18
  • 1
    @mathias and @Sungjun you saved my time, i have been trying for couple of days, My system has m1 chip and nothing was working for me. My system has multiple ruby versions conflicting with `Cocapods` , your solution fixed everything. – Farhana Naaz Ansari Mar 25 '22 at 09:25
  • i'm also using m1 chip, but not working, is it only me or there are a lot of problems with mac-flutter development? i find it very hard to setup and make it work – Ruelos Joel Jun 14 '22 at 17:27
  • Before you mindless copy/paste the instructions like we normally do to save time, first check if you have ruby installed : ```ruby --version``` and i recommend using ```rbenv``` to setup ruby if not install and then run ```gem install cocoapods``` to install. – Margach Chris Nov 02 '22 at 22:47
  • Amazing, searched a lot of other answers and did everything they said, it didn't work. BUT THIS DID! THANKS A LOT. YOU SAVED A LOT OF MY TIME. – Rajat Shenoi Jan 05 '23 at 13:30
10

Use brew and gem

  1. first uninstall by gem

    sudo gem uninstall cocoapods

  2. Install cocoapods by brew

    brew install cocoapods

  3. link using brew

    brew link --overwrite cocoapods

Amit Kumar
  • 1,503
  • 14
  • 11
5

First install brew package manager for Mac. https://brew.sh

If you use macOS, system Ruby is not recommended. and you should not use it. its for system specific use. you need to install another one for user.

brew install rbenv

then install the latest version of ruby. as today its 3.1.0

rbenv install 3.1.0 --verbose

then set the global version of Ruby to be used in all shells

rbenv global 3.1.0

close the terminal and reopen it again, to affect the changes.

and finally install cocoapods

gem install cocoapods

as you see you don't use sudo command. because you are not overriding system specific configurations. when you need to use sudo command means you are doing something that you should avoid it.

if you are using fastlane and still complaining about cocoapods, even cocoapods is installed properly, reinstall fastlane again:

brew uninstall fastlane
gem install fastlane

if you have issues with the ruby zlib extension when building 3.1.0:

  1. brew install zlib
  2. LDFLAGS=-L/usr/local/opt/zlib/lib CPPFLAGS=-I/usr/local/opt/zlib/include rbenv install 3.1.0
blkpingu
  • 1,556
  • 1
  • 18
  • 41
Hashem Aboonajmi
  • 13,077
  • 8
  • 66
  • 75
2
curl -L https://get.rvm.io | bash -s stable
rvm install ruby-2.6
rvm use ruby-2.6.5
rvm --default use 2.6.5
sudo gem update
sudo gem install ffi
brew install libffi
sudo gem install cocoapods
pod setup

this worked for me

CerebralFart
  • 3,336
  • 5
  • 26
  • 29
植植心
  • 406
  • 3
  • 5
0

sudo gem uninstall cocoapods
rvm install 2.6.5
sudo gem install cocoapods

0

I am using MacBook Pro (2020) with M1 and following steps worked


url -L https://get.rvm.io | bash -s stable

rvm install ruby-2.6

rvm reinstall ruby-2.6.6 

rvm use ruby-2.6.6

rvm --default use 2.6.6

sudo gem install cocoapods

Finally you can run flutter doctor to confirm.

flutter doctor

Output will be like this...

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.4, on macOS 12.4 21F79 darwin-arm, locale
    en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version
    32.0.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.68.1)
[✓] Connected device (1 available)
[✓] HTTP Host Availability
ViKi Vyas
  • 691
  • 5
  • 16
0

Please install latest version of ruby to solve this issue. Use this command

rvm install ruby

rvm use ruby

rvm --default use
stalin
  • 21
  • 3
0
sudo gem install -n /usr/local/bin cocoapods

Just run this command for installing the latest version of coc

My Car
  • 4,198
  • 5
  • 17
  • 50
0

This error took me about one week to solve :( The problem is mentioned clearly in the flutter output like this This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it. I had a lot of versions of ruby installed on my mac So this error happened to solve this error follow these steps

  1. remove or uninstall cocoapods
  2. remove all versions of ruby in your mac os except the system ruby version you can do that like this. https://mac.install.guide/ruby/9.html#:~:text=Uninstall%20Ruby%20on%20Mac%20with%20rbenv,command%20to%20remove%20a%20version.&text=This%20will%20remove%20any%20gems,recommendations%20of%20newer%20version%20managers.
  3. install ruby again using this link https://mac.install.guide/ruby/13.html
  4. install cocoapods with this command :- brew install cocoapods
0

@Aboonajmi's answer was really helpful but I would like to add something that may be more user-oriented in the case of Apple Chip M1/M2, for every command if you encounter fail result, add the "arch -arm64" for the command to run properly, for example:

arch -arm64 brew install rbenv

or

sudo arch -arm64 gem install cocoapods

Notice to use sudo when installing with gem.

Hope my information can be helpful.

ndnam198
  • 21
  • 5
0

With the latest version of Flutter (require ruby 2.7.2) so these steps below worked for me:

  1. curl -L https://get.rvm.io | bash -s stable
  2. rvm install ruby-2.7.2 
  3. rvm --default use 2.7.2 
  4. sudo gem install cocoapods
Hung Le
  • 1
  • 1