442

I have a Flutter project that I'm trying to run on iOS. It runs normally on my Intel-based Mac, but on my new Apple Silicon-based M1 Mac it fails to install pods.

LoadError - dlsym(0x7f8926035eb0, Init_ffi_c): symbol not found - /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi_c.bundle
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi.rb:6:in `rescue in <top (required)>'
/Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi.rb:3:in `<top (required)>'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Library/Ruby/Gems/2.6.0/gems/ethon-0.12.0/lib/ethon.rb:2:in `<top (required)>'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Library/Ruby/Gems/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus.rb:2:in `<top (required)>'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/sources_manager.rb:74:in `cdn_url?'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/sources_manager.rb:36:in `create_source_with_url'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/sources_manager.rb:21:in `find_or_create_source_with_url'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:178:in `block in sources'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:177:in `map'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:177:in `sources'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:1073:in `block in resolve_dependencies'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/user_interface.rb:64:in `section'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:1072:in `resolve_dependencies'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:124:in `analyze'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:414:in `analyze'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:239:in `block in resolve_dependencies'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/user_interface.rb:64:in `section'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:238:in `resolve_dependencies'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:160:in `install!'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/command/install.rb:52:in `run'
/Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/command.rb:52:in `run'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:23:in `load'
/usr/local/bin/pod:23:in `<main>'

Based on a Github workaround, I tried to run Terminal using rosetta, but the issue remains the same: https://github.com/CocoaPods/CocoaPods/issues/9907#issuecomment-655870749

Realising it's still early for Macs with Apple Silicon. Is there a way to make this work for the time being?

Şafak Gezer
  • 3,928
  • 3
  • 47
  • 49
Jacobo Koenig
  • 11,728
  • 9
  • 40
  • 75
  • Was unable to get it working without rosetta following the accepted answer, on a new M1 mac mini. Once installed via rosetta, its probably still running in compatibility mode, even if rosetta is later turned off. The correct answer is `Valentin Briand`'s answer below. A very outdated version of Ruby is installed on Macs by default. Whats needed is to install a newer ruby (easiest via homebrew), config terminal to use that version and then just install cocoapods as normal – Simon McLoughlin Jun 11 '21 at 13:46

40 Answers40

1013

2022 Nov Update

If you can use Homebrew to manage cocoapods.

# Uninstall the local cocoapods gem
sudo gem uninstall cocoapods

# Reinstall cocoapods via Homebrew
brew install cocoapods

2021 Solution

# STEP 1: Install ffi
sudo arch -x86_64 gem install ffi

# STEP 2: Re-install dependencies
arch -x86_64 pod install

Additional Information

#1 For anyone seeing the arch: posix_spawnp: gem: Bad CPU type in executable error, you must first install Rosetta. Thanks, @Jack Dewhurst

#2 If you run pod commands pretty often, setting up an alias in .zshrc or .bash_profile might be handy. Thanks, @theMoonlitKnight for the suggestion.

alias pod='arch -x86_64 pod'
XY L
  • 25,431
  • 14
  • 84
  • 143
  • 8
    I had the same error and followed the above method and pod got installed. I am using MacBook M1 – Praveen Dec 20 '20 at 18:56
  • 7
    @Metropolis, does this mean everytime I'm gonna install new pods, I'll be using this command `arch -x86_64 pod install`? – Adro Feb 11 '21 at 16:24
  • 1
    These commands worked for me, whereas the original answer did not. Thanks! – SuperTully Feb 25 '21 at 02:08
  • 15
    These commands work fine but you **have to use the system version of Ruby**. This did not work when i used Ruby 2.7 via rbenv – Nicolas Braun Mar 01 '21 at 10:03
  • 3
    This answer should be marked as the correct answer in 2021. – Hikeland Apr 02 '21 at 16:59
  • 5
    arch: posix_spawnp: gem: Bad CPU type in executable – jignesh.world May 03 '21 at 09:54
  • Not Working in MacMINI. Getting this error "arch: posix_spawnp: pod: Bad CPU type in executable" – Mahadhi Hassan Chowdhury Sep 15 '21 at 04:55
  • 1
    So until there's an ffi update, instead of `pod install` we need `arch -x86_64 pod install` every time? – bauerMusic Oct 13 '21 at 13:32
  • 1
    Rocking the M1X and this is still an issue, thanks for the help! – Anthony Sette Oct 28 '21 at 17:57
  • 1
    Put `alias pod='arch -x86_64 pod'` in .zshrc or .bash_profile to just type `pod install` – theMoonlitKnight Nov 25 '21 at 13:32
  • @xinyang I used these methods but for a firebase project its not working? any idea – Ananthakrishna Nov 25 '21 at 18:53
  • 1
    For anyone seeing the `arch: posix_spawnp: gem: Bad CPU type in executable` error you must first install Rosetta. – Jack Dewhurst Nov 29 '21 at 22:29
  • [!] Oh no, an error occurred. on Mac M1 – TomV Dec 03 '21 at 15:56
  • Only partially works: pod install works fine. pod update has this error: LoadError - dlopen(/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.4/lib/ffi_c.bundle, 0x0009): tried: '/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.4/lib/ffi_c.bundle' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/lib/ffi_c.bundle' (no such file) - /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.4/lib/ffi_c.bundle /System/Library/Fr – TomV Dec 16 '21 at 13:54
  • Second step gives me this: `arch: Can't find pod in PATH` – Tautvydas Feb 02 '22 at 08:13
  • In my case. Just open `.zshrc` and put `alias pod='arch -x86_64 pod'` in the end of line – mducc Feb 09 '22 at 03:40
  • @NicolasBraun how did you get it to work with rbenv? – razvan Feb 20 '22 at 18:20
  • 2
    Feb 2022 - this works. Lots of outdated answers here because native Apple Silicon only started working recently with CocoaPod. Kudos for updating this answer! – n13 Feb 27 '22 at 04:35
  • You copied my answer and edited yours. That's not fair. – pravchuk Mar 04 '22 at 03:24
  • 3
    "2022 Update" works on M1! – Volkov Maxim Mar 05 '22 at 17:10
  • If you get error to install cocoapods use "sudo gem install cocoapods " – Amon C Mar 09 '22 at 06:17
  • Can someone explain what arch -x86_64 is? Just curious because this is the second time I've revisited this page due to firebase issues and it's also a year later and only the 2021 answer works for me despite the timeline. – IamToobDude Mar 14 '22 at 16:21
  • Installing cocoapods via brew doesn't work if you're trying to use `cocoapods-keys`. Installing ruby through homebrew worked for me (as in this answer: https://stackoverflow.com/a/66556339/3462536) -- See issue thread in cocoapods-keys here: https://github.com/orta/cocoapods-keys/issues/217 – NineToeNerd Mar 19 '22 at 02:32
  • Try not to use Terminal with Rosetta – Cyber Apr 07 '22 at 13:31
  • Confirm this solution works for Monterey 12.3.1 (updated 2022-May) – Chutipong Roobklom May 16 '22 at 03:34
  • 1
    after installing cocoapods using homebrew, i get command not found on zsh – gaurav5430 Jul 01 '22 at 05:45
  • 1
    I have a MacBook M1 and using Homebrew was the solution, thanks for sharing – Frank Eno Jul 15 '22 at 10:20
  • M2 MacBook Air here. Confirming this worked. For those curious, Homebrew is a package manager for Mac. Installation instructions @ https://brew.sh. – theogood Aug 24 '22 at 15:16
  • `brew install cocoapods` gives an error: Error: The `brew link` step did not complete successfully The formula built, but is not symlinked into /usr/local Could not symlink bin/xcodeproj Target /usr/local/bin/xcodeproj already exists. You may want to remove it: rm '/usr/local/bin/xcodeproj' – auspicious99 Sep 04 '22 at 04:57
  • 3
    after updating to xcode 14, the cocoapods version from homebrew fails with errors – Michael Ndiritu Sep 27 '22 at 12:37
266

EDIT: I recently disabled Rosetta, and Cocoapods runs just fine with the addition of the ffi gem.

For anyone else struggling with this issue, I just found a way to solve it. In addition to running terminal in Rosetta:

  1. Right-click on Terminal in Finder
  2. Get Info
  3. Open with Rosetta

I installed a gem that seems to be related to the symbol not found in the error:

sudo gem install ffi

After doing this, cocoapods runs as expected.

Jacobo Koenig
  • 11,728
  • 9
  • 40
  • 75
257

TL;DR:

  • Install your own version of Ruby with Homebrew / rbenv / RVM (e.g. brew install ruby)
  • Add it and the gems binaries to your PATH and make sure the new version is used with which ruby (should be /opt/homebrew/opt/ruby/bin/ruby instead of /usr/bin/ruby if installed with Homebrew)
  • Install CocoaPods with sudo gem install cocoapods (make sure ethon is at least version 0.13.0)
  • Run pod install

Detailed answer:

All answers suggesting using Rosetta / arch -x86_64 are workarounds and not quite solving the real issue that comes from the way RbConfig and the universal binaries work.

require 'rbconfig'

OSVERSION = RbConfig::CONFIG['host_os']
ARCH = RbConfig::CONFIG['arch']
HOSTCPU = RbConfig::CONFIG['host_cpu']
BUILDCPU = RbConfig::CONFIG['build_cpu']
TARGETCPU = RbConfig::CONFIG['target_cpu']

puts "OS: #{OSVERSION}"
puts "Arch: #{ARCH}"
puts "Host CPU: #{HOSTCPU}"
puts "Build CPU: #{BUILDCPU}"
puts "Target CPU: #{TARGETCPU}"

If you call ruby on a file containing this code with the universal binary shipped with macOS, you will get the following result on an M1 Mac:

OS: darwin20
Arch: universal-darwin20
Host CPU: x86_64
Build CPU: x86_64
Target CPU: universal

As you can see, RbConfig was compiled for a « universal » CPU but built with an x86 CPU, and the rbconfig.rb file that was generated (see /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin20/rbconfig.rb) consequently uses invalid information for the host CPU.

As ffi uses information from RbConfig (see https://github.com/ffi/ffi/blob/dfae59e293974efaa7b4d414e5116d7a2187a06e/lib/ffi/platform.rb#L61 and https://github.com/ffi/ffi/blob/e3f2cf9b82055709ddbeecbf77810f43438c4b64/spec/ffi/fixtures/compile.rb#L11), we end up with OP’s error message.

The solution is, therefore, to get a version of Ruby built specifically for arm64 by using either Homebrew, rbenv or RVM.

For Homebrew:

  • Execute brew install ruby
  • Add export PATH=/opt/homebrew/opt/ruby/bin:/opt/homebrew/lib/ruby/gems/3.0.0/bin:$PATH to your .zshrc (you can find your Homebrew installation directory with $(brew --prefix) if needed)
  • Execute source ~/.zshrc or restart your shell
  • Make sure you are using the correct ruby binary by executing which ruby (should be $(brew --prefix)/opt/ruby/bin/ruby)
  • Install CocoaPods with sudo gem install cocoapods
  • Make sure you are using the correct pod binary by executing which pod (should be $(brew --prefix)/lib/ruby/gems/3.0.0/bin/pod)
  • Make sure ethon is version 0.13.0 or more with gem info ethon, otherwise run sudo gem install ethon
  • Run pod install

Ruby won't come with future macOS versions by default

Moreover, it should be noted that ruby is still included in macOS only « for compatibility with legacy software », as evidenced by running irb -v, so this is probably a good opportunity to install your own version anyway:

WARNING: This version of ruby is included in macOS for compatibility with legacy software. In future versions of macOS the ruby runtime will not be available by default and may require you to install an additional package.

irb 1.0.0 (2018-12-18)

Sources:

auspicious99
  • 3,902
  • 1
  • 44
  • 58
Valentin Briand
  • 3,163
  • 2
  • 8
  • 17
  • I was having exactly the experience you describe here. Tried applying the patch for `ethon` locally, but same `Segmentation fault` error was happening. What seemed to work for me (after having `ruby --version` as `arm64-darwin20`) was installing an older version of cocoapods (`1.5.2`) – Endel Dreyer Mar 18 '21 at 00:55
  • Followed every step but was only able to make pods to install after manually installing the latest typhoeus/ethon gem from github (which already includes the patch in the latest commit as of March 28 3e87140...). thanks for diving deep into the issue! – Shengchalover Mar 28 '21 at 22:17
  • ethon 0.13.0 is out. Thank you for your research. – El Horrible Apr 11 '21 at 23:06
  • 26
    "arch -x86_64" is a hack to just get things working, so this should be the accepted answer. Works perfectly. – Chris Douglass Apr 13 '21 at 00:05
  • @ValentinBriand I installed cocoapods using brew (/opt/homebrew/bin/pod) and it seems it all works (I am using ruby 3.0.1p64). I have ethon 0.12.0 on system ruby but that is not used. – El Horrible Apr 14 '21 at 11:12
  • 4
    I done the steps but which pod still gives me `/usr/local/bin/pod` path. Other steps are correct. How can I change pod location to ruby one? – Emre Önder May 09 '21 at 09:51
  • @EmreÖnder do `which ruby` and `which gem` point to your Homebrew directory? If not, make sure that `/opt/homebrew/opt/ruby/bin` is before `/usr/bin` in your `PATH` – Valentin Briand May 09 '21 at 11:34
  • 6
    Yes `which ruby` and `which gem` shows me the correct directory. I uninstalled cocapods and reinstall it but didn't work. If I type `$(brew --prefix)/lib/ruby/gems/3.0.0/bin/pod) install` rather than `pod install` It is working. Somehow, cocapod seems `usr/bin` rather than ruby path – Emre Önder May 09 '21 at 11:38
  • 8
    This works. Forget the "arch -x86_64" circumvention in the other answers. – vilmoskörte May 12 '21 at 11:11
  • 1
    Thanks, this work for my. With my Xcode work space, also need to update Carthage script path to run success. Thanks again. – lee Jul 12 '21 at 09:37
  • 3
    @EmreÖnder did you ever solve this? My M1 computer arrived today and can't get pod to point to the right ruby. – Mike Portanova Oct 26 '21 at 23:10
  • 2
    @MikePortanova I can help you. This works like a charm on my new iMac. First, run `brew --prefix`. Let's say the result is `mikes/path`. Then the changes for you would be `export PATH=mikes/path/opt/ruby/bin:mikes/path/lib/ruby/gems/3.0.0/bin:$PATH`. Now `which ruby` and which pod should return `mikes/path/opt/ruby/bin/ruby` and `mikes/path/lib/ruby/gems/3.0.0/bin/pod` respectively after you install ruby and cocoa pods as mentioned in the answer. – Kartik Watwani Nov 04 '21 at 18:31
  • Great answer! But `which pod` returns `/opt/homebrew/bin/pod` for me. It seems to run fine. How do I point to the correct pod binary? – SmileBot Nov 06 '21 at 16:16
  • 1
    @smileBot I think it's fine since `which pod` is pointing to your homebrew directory. Also, `/opt/homebrew/bin/pod` is likely a symlink so check where it points to. – Valentin Briand Nov 07 '21 at 12:56
  • @ValentinBriand Ok great. It is a symlink pointing to `/opt/homebrew/Cellar/cocoapods/1.11.2_1/bin/pod`. – SmileBot Nov 07 '21 at 18:00
  • incredible!! after 2-3 hours of searching this fixed it.. thank you. – aheigins Nov 26 '21 at 15:33
  • This really should be the accepted answer. It's not a workaround. Also note that if you installed cocoa pods before installing Homebrew, make sure to temporarily comment out the Homebrew path from your .zshrc file (or bash version), fully uninstall cocoa pods then add the Home-brew path back. Otherwise there terminal will use the non-Homebrew version of cocoa pods (at least that was my experience). – Christian Gossain Nov 27 '21 at 18:22
  • 1
    Do not read only the TL;DR, read the "For Homebrew" list that explains each step, in particular how to set up the PATH correctly. – Albert James Teddy Nov 28 '21 at 10:43
  • Works fine! To have 'which pod' to show the proper version of CocoaPods, I had to restart my terminal. Followed the brew path. – sergevm Dec 06 '21 at 20:57
  • This should be the correct answer. Thank you for the detailed explanation. Worked fantastic on my 2021 MacBook Pro M1 Max. – CoBrA2168 Dec 14 '21 at 01:37
  • I used `asdf` as my ruby version manager and this works fine...as long as you remember to remove any CocoaPods install (`sudo /usr/bin/gem uninstall cocoapods`) you may have done earlier with the ancient system Ruby, or ! That placed the `pod` command in `/usr/local/bin`, which was picked up first in my PATH instead of the asdf shim. – qix Dec 29 '21 at 16:10
  • To set the Homebrew-installed Ruby to take priority over the system Ruby I need set ```if [ -d "/opt/homebrew/opt/ruby/bin" ]; then export PATH=/opt/homebrew/opt/ruby/bin:$PATH export PATH=`gem environment gemdir`/bin:$PATH fi``` on my `~/.zshrc`. For the complete guide see https://mac.install.guide/ruby/13.html – Lucas Garcez Jan 06 '22 at 16:18
  • 1
    brew install ruby Running `brew update --preinstall`... ==> Auto-updated Homebrew! Updated 1 tap (homebrew/core). ==> Updated Formulae Updated 1 formula. Error: Cannot install under Rosetta 2 in ARM default prefix (/opt/homebrew)! To rerun under ARM use: arch -arm64 brew install ... To install under x86_64, install Homebrew into /usr/local. – 1nstinct Jan 20 '22 at 23:46
  • Excellent answer and worked for me. Wish this could be pinned to the top – achow Jan 23 '22 at 23:13
  • Thanks a lot to explain the main reason for understand the problem @ValentinBriand The 16k reputation should be yours xDDD – Kalamarico Feb 02 '22 at 22:57
  • How do I add the path for this part? " Make sure you are using the correct pod binary by executing which pod (should be $(brew --prefix)/lib/ruby/gems/3.0.0/bin/pod) " – IamToobDude Mar 15 '22 at 18:09
  • For the `PATH`, I added `export PATH="$PATH:\`gem environment gemdir\`/bin"` to my `~/.profile` – sjmeverett May 24 '22 at 15:27
  • 1
    I tried so many solutions to make it work that it never did, it's been 3 months since I bought this mac, which is even damaged beyond salvage-able and even then, I've finally managed to make iOs development work. @1nstinct The problem was Rosetta, I disabled it for Terminal, then followed this answer, also reminding people to also uninstall `ffi` you won't need that with this answer, not uninstalling it will give architecture problems. – Lalit Fauzdar Sep 16 '22 at 12:01
  • 1
    Interesting... after foraging the internet and encountering a lot of "noise", this finally worked – Makari Kevin May 26 '23 at 08:02
  • Add the Homebrew Ruby to PATH using sudo vim /etc/paths, and include /opt/homebrew/opt/ruby/bin at the top of the list. – AliSh Jul 26 '23 at 12:53
  • If you're here because of kotlin multiplatform check this answer: https://stackoverflow.com/questions/64901180/how-to-run-cocoapods-on-apple-silicon-m1/76800022#76800022 – Edylson Frederico Jul 31 '23 at 20:44
71

To install completely cocoapods on Mac with M1 chip (Apple Silicon), please follow these steps:

  1. Duplicate the Terminal application in the Utilities folder.
  2. Right-click on the app and choose to Get Info.
  3. Rename the other version of the app as you like.
  4. Check the option "open with Rosetta".
  5. Install Cocoapods with the command "sudo gem install cocoapods"
  6. Type the command line "gem install ffi" to fix the ffi bundle problem. Now you can do a "pod install" without a problem.

Source : iPhoneSoft

auspicious99
  • 3,902
  • 1
  • 44
  • 58
Medhi
  • 2,656
  • 23
  • 16
38

Simplest way I found :

sudo gem uninstall cocoapods

brew install cocoapods

pravchuk
  • 903
  • 10
  • 14
  • This works great. I also did `brew install libffi` for using some 3rd party libs with flutter. the `gem` shipped from macOS isn't cool. – dotslash Jan 26 '22 at 03:10
26

An alternative to running Terminal in Rosetta 2 is to set the architecture with arch -x86_64, as in the following:

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

To give credit where it is due, I found this solution here

MacPorts bug tracker, issue #61545, comment 7

pfurbacher
  • 1,789
  • 3
  • 15
  • 23
19
  1. Execute below to install the required ffi :

    sudo arch -x86_64 gem install ffi

  2. Instead of pod install use :

    arch -x86_64 pod install

Harshit Jain
  • 885
  • 11
  • 15
12

There is a much "better/easier?" way by way of using homebrew now that waters have settled, if you have homebrew install just run

brew install cocoapods

this will install ruby and libyaml as preconditions, so far this is the most straightforward way (and the one, most probably, to be recommended moving forward).

samiq
  • 2,954
  • 1
  • 29
  • 29
11

Basically tried all solutions listed here.

$ arch -arm64 brew install cocoapods

finally did it for me.

Before doing that, be sure to have homebrew correctly installed with /opt/homebrew being the prefix. This article provides pretty good instructions on this.

Edit: Another option is to remove all your flutter and dart files and just use homebrew for the complete installation process as shown here. This also worked for me on M1 Pro.

Matteo
  • 179
  • 1
  • 8
10

UPDATE 28th MARCH

1- arch -x86_64 sudo gem install cocoapods -n /usr/local/bin

2- arch -x86_64 sudo gem install ffi

3- pod install

No need to duplicate or Open with Rosetta

Jad
  • 2,139
  • 1
  • 16
  • 28
8

Working in Sept 2021, Mac M1

I just want to add to Medhi's answer, to do a "pod repo update" within the same terminal inside the iOS folder, because that was critically fixing the error for me.

Here's the complete To-do-list:

  1. Duplicate the Terminal application in the Utilities folder.

  2. Right click on the app and choose "Get Info".

  3. Rename the other version of the app as you like.

  4. Check the option "open with Rosetta".

  5. Install Cocoapods with the command sudo gem install cocoapods

  6. Type the command line sudo gem install ffi to fix the ffi bundle problem.

  7. Go to the iOS folder of your app in the same terminal

  8. Do pod repo update

  9. Now you can do a pod install without a problem.

LW001
  • 2,452
  • 6
  • 27
  • 36
username
  • 126
  • 1
  • 6
  • Could you please link to the answer you're adding to instead of the user auspicious99? They have edited two answers to this question and it's not clear which one you meant to add to. You can copy the link to an answer using the "Share" button below it and [edit] your post to contain the URL of the answer. – LW001 Sep 01 '21 at 19:48
  • @LW001 I did the edit - makes sense! Thank you so much! – username Sep 02 '21 at 08:23
  • oh gosh that was it!! pod repo update – Andrey Poznyak Oct 25 '22 at 14:27
8

Please use this below code: -

arch -x86_64 pod install

This will definitely work, under any circumstances.

Sagar Ghag
  • 105
  • 2
  • 4
7

✅ The following solution work for me on my Apple M1 machine.

I've spent over a week searching for a solution to install CocoaPods successfully on a M1 machine. You may see if my method works for you or not.

The solution requires the Terminal.app to be running in "Rosetta" mode.

But it does not required the Terminal to be running in x86.

[Environment]

Mac mini (M1, 2020) / macOS Big Sur (Version 11.5.2) / Xcode Version 13.0 (13A233)


Terminal + Rosetta

(Rosetta is required on CocoaPods installation)

To run the terminal.app in "Rosetta" mode,

Right click the Terminal.app > Select "Get Info" > Make sure "Open using Rosetta" is checked.

Image showing a checkbox with item "Open using Rosetta" is checked.


Steps

(1) Run the following lines for updating gem.

Make sure you gem version is up-to-date before executing any commands following. The update is introduced by this article on Medium.

sudo gem update -n /usr/local/bin --system

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

(2) Execute the commands using the "sudo" command.

sudo gem install

(3) Install an older version of CocoaPods

As the latest version (1.10.0) cannot be installed for my case. I've tried installing an older version. The line execute successfully without any error messages.

You may check the thread on Apple's forum.

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

Solutions on Error

Then, the compiler may bring you some error, like "active developer path do not exist". This error would shown if you've installed a beta version of Xcode on your machine.

You would need run following lines for the compiler to switch to a new active path, pointing to the new Xcode app.

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

If your Xcode refuses to switch, you may check out this thread on Apple's forum to see if it helps.


Final Step ⬇️

(1) Uncheck "Open using Rosetta"

Then, may go back to the "info" panel and uncheck "Open using Rosetta", but unchecking Rosetta is optional. You may keep the box checked if it is needed.

(2) Run CocoaPods commands as usual

After that, you can back to the project directory and run commands pod init to initiate the CocoaPods for your project as usual

Steps for a normal CocoaPods build:

  1. pod init
  2. open Podfile
  3. edit Podfile (for specifying pods)
  4. pod install
  5. The .xcworkspace is ready to be opened in Xcode.

Use sudo xcodebuild -license if you've faced an error (regarding to Xcode registration).

Nimantha
  • 6,405
  • 6
  • 28
  • 69
21.kaw
  • 583
  • 2
  • 7
  • 18
6

Install cocoapods

sudo arch -x86_64 gem install ffi

Install pod file

arch -x86_64 pod install

Update pod

arch -x86_64 pod update
6

Pod Not installing on M1 Chip MAC ??? No worries

run below three commands : -

pod deintegrate

sudo arch -x86_64 gem install ffi

arch -x86_64 pod install

it works !!

Govind Wadhwa
  • 904
  • 8
  • 16
6

Mac M1 MacOS BigSur solution:

brew cleanup -d -v    
brew install cocoapods
brew link --overwrite cocoapods
Michał Dobi Dobrzański
  • 1,449
  • 1
  • 20
  • 19
5

If your case is that you've updated your project and already have ffi installed, you will need to run this:

arch -x86_64 pod install --repo-update
Rafael Affonso
  • 181
  • 3
  • 6
4

Try $ sudo gem install ffi. It works fine for me.

Kevin
  • 51
  • 1
4

this is what i got when trying to instal ffi in native terminal:

Fetching ffi-1.13.1.gem
Building native extensions. This could take a while...
ERROR:  Error installing ffi:
    ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/ext/ffi_c

switching to Rosetta enabled terminal, installing "gem install cocoapods" fails on

You don't have write permissions for the /usr/bin directory.

but then installation of ffi was successful...

Finally solved it with

sudo gem install cocoapods -n /usr/local/bin
An Chin
  • 463
  • 5
  • 8
4

I had the same issue and this is what helped me. Open the terminal and type the below command :

arch -x86_64 sudo gem install ffi
ABM
  • 565
  • 7
  • 18
4

As of version 1.10.1 Jan 7, 2021, CocoaPods is now supporting the new M1 chip.

Ahmed Kamal
  • 2,660
  • 3
  • 21
  • 36
  • I have this version, but I still need to prefix all commands with `arch -x86_64` – tontonCD Jul 21 '21 at 06:47
  • @tontonCD if you're coming from an older version, uninstalling and reinstalling CocoaPods might fix this for you. please confirm if you had the chance to do so. – Ahmed Kamal Jul 24 '21 at 07:41
  • No, sorry, my M1 is new, it's the first time I install cocoa pod. It suggests that uninstalling is not sufficient... but perhaps mandatory... – tontonCD Jul 26 '21 at 08:59
4

IN MAC M1, for anyone using KMM (Kotlin Multiplatform Mobile), but it may work for other, finding that it does not create files on the .xcworkspace for the iOS APP, when using CocoaPods as dependency manager, first install CocoaPods by typing

sudo gem install cocoapods

than navigate to your project folder, now on the iOS folder and type

sudo arch -x86_64 gem install ffi
arch -x86_64 pod install

Now you should find all the files in iOS workspace. If you have problems with

/Users/$name/$directory/$projectName/$iosFolderName/$iosAppName.xcodeproj 
The linked and embedded framework 'Pods_iosApp.framework' is missing one or more architectures required by this target: x86_64.

You need to add arm64 to xCode, click on the project folder -> Build Settings -> and search for Excluded Architectures and add arm64

WaSderino
  • 41
  • 4
4

This is how I solved my problem in M1. Someone might be helped.

From System preference. User & group. Set login shell as

   /bin/bash 

Then close the terminal and reopen it.run this command

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

Hopefully, this will works.

Shourob Datta
  • 1,886
  • 22
  • 30
3

I've been having the same issue. I did find that the cocoa pods UI app seems to work as expected.

Stropdale
  • 46
  • 2
3

For updating pods, maybe someone will help:

After installing ffi:

sudo arch -x86_64 gem install ffi

Update dependencies

arch -x86_64 pod update
pajtimid
  • 518
  • 1
  • 4
  • 13
3

Kotlin Multiplatform Mobile Development

If you're here because you got this error while running kdoctor

ruby@2.7 is working for me so:

brew install ruby@2.7

Switch to the newly installed Ruby version:

brew link --overwrite ruby@2.7

Then install CocoaPods:

brew install cocoapods
2

Install pod in project without using rosetta terminal just follow below steps

  • sudo arch -x86_64 gem install ffi
  • arch -x86_64 pod install
Bhadresh11
  • 29
  • 3
1

I have a twist to this answer:

  1. run
sudo gem install ffi
  1. the twist: I restarted my machine and then it worked.
ScottyBlades
  • 12,189
  • 5
  • 77
  • 85
1

I had the same problem with my new MacBook Air M1 just because m1 has a different architecture we should install packages with Rosetta Translation Environment.

You can solve most compatibilities by using rosetta.

STEPS TO SOLVE:

  1. Open finder/applications
  2. Duplicate your terminal
  3. Right-click the new terminal and check the checkbox [x] open using

and then install packages with this terminal enter image description here

1

If you Are using M1 chip system then use-

go to application folder-

select terminal open with rosseta- then run cmd-

sudo arch -x86_64 gem install ffi

Then

arch -x86_64 pod install
Md Tariqul Islam
  • 2,736
  • 1
  • 20
  • 35
Rohit Nishad
  • 428
  • 4
  • 7
1

Click right and open get info menu Check "Open using rosetta"

sudo gem install cocoapods

sudo gem install ffi

sudo gem update --system // Update ruby

If it doesn't work:

Install a ruby manager, I preferred rvm

rvm install:

  • $brew install gnupg
  • gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
  • \curl -sSL https://get.rvm.io | bash

Don't forget to add bash profile:

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to path for scripting (to manage Ruby versions) export PATH="$GEM_HOME/bin:$PATH" [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session as a function

  • Check

$rvm -list

command if rvm is installed successfully

  • Install new ruby version:

$rvm install 3.1.2

  • Select default version:

$rvm --default use 3.1.2

Then restart the terminal and run $sudo gem install cocoapods

erdikanik
  • 674
  • 9
  • 11
1

I have got solution for this for cocoapods installation.

There is basically 2 ways to install cocoa pods.

1. install cocoapods via Homebrew:

brew install cocoapods

2. install cocoapods via gem:

sudo gem install ffi

if you are facing issue with Apple M1 or Apple M2 chip

First terminal with Rosetta

  • Right click on the Terminal application and select op.
  • Right click on the app and choose "Get Info".
  • Check the option "open with Rosetta".

enter image description here

you may go for following command:

sudo arch -x86_64 gem install ffi

once finish installation try with following command:

arch -x86_64 pod install
Mr.Javed Multani
  • 12,549
  • 4
  • 53
  • 52
0

I did get this problem after new dependencies (Firebase) where added to the repo. Was then able to do the sudo arch -x86_64 gem install ffi, but other problems remained after it.

My fix was: re-cloning the repo and running it again.

Setup: Xcode 12.4 Mac M1 react-native 63.4

Patrik Rikama-Hinnenberg
  • 1,362
  • 1
  • 16
  • 27
0

the solution for me was to add arch -x86_64 at the begining of the create command

Blue
  • 15
  • 2
0

This is what worked for me, trying to build app on Mac M1

first go to your applications folder and

select terminal app -> get info -> select run with rosseta

// if you are trying to build the app through xcode Repeat the above steps for xcode app

Note: Make sure your terminal and code are closed while doing so.

Now run your terminal switch to your project_folder/ios

Run below-shown commands

sudo gem install cocoapods

sudo gem install ffi

sudo arch -x86_64 gem install ffi
Vicky Salunkhe
  • 9,869
  • 6
  • 42
  • 59
0

All of the above solutions are valid, just wanted to post that with home brew and cocoapods supports native Apple Silicon chips you can run the command without prefixing arch -x86_64

so, sudo gem install ffi will do the job.

Hamza Jadid
  • 388
  • 4
  • 17
0

we can easily fix this problem

  1. Click on Finder
  2. go to applications
  3. right click on xcode
  4. click on get info
  5. checkmark the open using Rosetta enter image description here
Zain Ahmed
  • 179
  • 2
  • 3
0

As of Nov 2022. Did the following on a 2021 M1 iMac and it works.

# uninstall cocoapods
sudo gem uninstall cocoapods

# Optional; unshallow homebrew core
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow

# Install homebrew to right locations; from https://brew.sh/
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add shortcuts as prompted at the end of running the above command
echo '# Set PATH, MANPATH, etc., for Homebrew.' >> $HOME/.bash_profile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> $HOME/.bash_profile
eval "$(/opt/homebrew/bin/brew shellenv)"

# Install cocoapods
brew install cocoapods

# Further, install Vim; taken from https://formulae.brew.sh/formula/vim
brew install vim
CodeBrew
  • 6,457
  • 2
  • 43
  • 48
0

Currently, ARCHFLAGS can be used to create a univeral binary install of cocoapods with the system Ruby shipped by Apple.

sudo env ARCHFLAGS='-arch arm64 -arch arm64e -arch x86_64' \
  gem install cocoapods

## needed for compatibility with system Ruby currently shipping with Ventura 
sudo env ARCHFLAGS='-arch arm64 -arch arm64e -arch x86_64' \
  gem install activesupport -v 6.1.7.3

## verify that universal binaries were installed:
CHECK_DIR="/Library/Ruby"
find "$CHECK_DIR" -name "*.bundle" | xargs file

# /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-22/2.6.0/ffi-1.15.5/ffi_c.bundle: Mach-O universal binary with 3 architectures: [x86_64:Mach-O 64-bit bundle x86_64] [arm64:Mach-O 64-bit bundle arm64] [arm64e:Mach-O 64-bit bundle arm64e]
# /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-22/2.6.0/ffi-1.15.5/ffi_c.bundle (for architecture x86_64):  Mach-O 64-bit bundle x86_64
# /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-22/2.6.0/ffi-1.15.5/ffi_c.bundle (for architecture arm64):   Mach-O 64-bit bundle arm64
# /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-22/2.6.0/ffi-1.15.5/ffi_c.bundle (for architecture arm64e):  Mach-O 64-bit bundle arm64e
# /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/ext/ffi_c/ffi_c.bundle:                       Mach-O universal binary with 3 architectures: [x86_64:Mach-O 64-bit bundle x86_64] [arm64:Mach-O 64-bit bundle arm64] [arm64e:Mach-O 64-bit bundle arm64e]
# /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/ext/ffi_c/ffi_c.bundle (for architecture x86_64):    Mach-O 64-bit bundle x86_64
# /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/ext/ffi_c/ffi_c.bundle (for architecture arm64): Mach-O 64-bit bundle arm64
# /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/ext/ffi_c/ffi_c.bundle (for architecture arm64e):    Mach-O 64-bit bundle arm64e
# /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle:                             Mach-O universal binary with 3 architectures: [x86_64:Mach-O 64-bit bundle x86_64] [arm64:Mach-O 64-bit bundle arm64] [arm64e:Mach-O 64-bit bundle arm64e]
# /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle (for architecture x86_64):  Mach-O 64-bit bundle x86_64
# /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle (for architecture arm64):   Mach-O 64-bit bundle arm64
# /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle (for architecture arm64e):  Mach-O 64-bit bundle arm64e

Tested on both an Apple Intel mini and an Apple Silicon mini. Each had a clean macOS Ventura 13.4 install with Xcode 14.3.1 (14E300c) on the boot drive.

The Apple Intel mini can create a universal binary with multiple Instruction Set Architecture (ISA) slices. However, the Intel can only run and test the native x86_64. The Apple Silicon mini with Rosetta enabled can run|test all of the arm64, arm64e, and x86_64 ISA binary slices.

marc-medley
  • 8,931
  • 5
  • 60
  • 66
-1

If you are on an older project that needs to be ported over don't forget to update the project.pbxproj files in your Runner.xcodeproj and Pods.xcodeproj.

The IPHONEOS_DEPLOYMENT_TARGET probably is still pointed towards 8.0

Update all occurrences as follows:

IPHONEOS_DEPLOYMENT_TARGET = 9.0;
Xan
  • 1