Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error installing ffi: ERROR: Failed to build gem native extension. (Apple M1) #937

Open
andesappal opened this issue Jan 24, 2022 · 29 comments

Comments

@andesappal
Copy link

andesappal commented Jan 24, 2022

kevin@Kevins-MacBook-Air ~ % sudo arch -x86_64 gem install ffi
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.15.5/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20220124-41484-17xcahw.rb extconf.rb
checking for ffi.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
	--with-ffi_c-dir
	--without-ffi_c-dir
	--with-ffi_c-include
	--without-ffi_c-include=${ffi_c-dir}/include
	--with-ffi_c-lib
	--without-ffi_c-lib=${ffi_c-dir}/lib
	--enable-system-libffi
	--disable-system-libffi
	--with-libffi-config
	--without-libffi-config
	--with-pkg-config
	--without-pkg-config
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header'
	from extconf.rb:10:in `system_libffi_usable?'
	from extconf.rb:42:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.15.5/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.15.5/gem_make.out
kevin@Kevins-MacBook-Air ~ % 
@andesappal andesappal changed the title Error installing ffi: ERROR: Failed to build gem native extension. Error installing ffi: ERROR: Failed to build gem native extension. (Apple M1) Jan 24, 2022
@southwolf
Copy link

southwolf commented Mar 20, 2022

You have to install development tools first.
@andesappal
Could you check if you have XCode Command Line Tools installed?
by running xcode-select --install

@sryze
Copy link

sryze commented Jul 20, 2022

Same error on Catalina. Development tools are already installed.

$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

Ruby version:

ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19

Log:

$ cat /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.15.5/mkmf.log
"pkg-config --exists libffi"
| pkg-config --libs libffi
=> "-lffi\n"
"xcrun clang -o conftest -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19 -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib -L. -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/usr/local/lib   -arch x86_64   -lruby.2.6   "
In file included from conftest.c:1:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby.h:33:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
         ^~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: note: did not find header 'config.h' in framework 'ruby' (loaded from '/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks')
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

On my system, ruby/config.h is located in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin20. Maybe that's the issue?

@sryze
Copy link

sryze commented Jul 20, 2022

It seems that the build script is using the wrong include directory - universal-darwin19 instead of universal-darwin20. Creating a link for that directory fixed the issue for me.

sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin20 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19

@ajith-acumen
Copy link

kevin@Kevins-MacBook-Air ~ % sudo arch -x86_64 gem install ffi
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.15.5/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20220124-41484-17xcahw.rb extconf.rb
checking for ffi.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
	--with-ffi_c-dir
	--without-ffi_c-dir
	--with-ffi_c-include
	--without-ffi_c-include=${ffi_c-dir}/include
	--with-ffi_c-lib
	--without-ffi_c-lib=${ffi_c-dir}/lib
	--enable-system-libffi
	--disable-system-libffi
	--with-libffi-config
	--without-libffi-config
	--with-pkg-config
	--without-pkg-config
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header'
	from extconf.rb:10:in `system_libffi_usable?'
	from extconf.rb:42:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.15.5/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.15.5/gem_make.out
kevin@Kevins-MacBook-Air ~ % 

@ajith-acumen
Copy link

i hot same error how to fix it

@jabiel
Copy link

jabiel commented Nov 22, 2022

Thanks! In my case it was creating a link universal-darwin21 which directs to universal-darwin22

It seems that the build script is using the wrong include directory - universal-darwin19 instead of universal-darwin20. Creating a link for that directory fixed the issue for me.

sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin20 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19

@funky-monkey
Copy link

Having the same issue. Adding the symlink did not work.
I was just reading this issue and OP hinted at removing spaces in the build path.

topdir and arch_hrdir seem to escape or quote the path, but includedir doesn't, so I'm assuming that's where the issue lies.

Removing the space in the pathname solved my issue.

@hefler
Copy link

hefler commented Dec 13, 2022

Solved by removing any whitespace character as pointed out by @funky-monkey

Removing the space in the pathname solved my issue.

PS: I'm on an Mac Intel, so I don't think it's related to different chip architectures

@mareFernando03
Copy link

It seems that the build script is using the wrong include directory - universal-darwin19 instead of universal-darwin20. Creating a link for that directory fixed the issue for me.

sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin20 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19

How can I know wich directory i need include?

@DigitalSolomon
Copy link

DigitalSolomon commented Dec 31, 2022

Here's what I did, this might help you @mareFernando03 :

  1. Open up the mkmf.log file mentioned in the output from the failed ffi installation. For me, this was at /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-21/2.6.0/ffi-1.15.5/mkmf.log.
  2. Look at the paths being referenced in the xcrun clang command, nearby the -I parameter. For me this is /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin21
  3. Navigate in Finder to the directory that is the parent of the universal-darwinXX directory to see what files you have in there (or cd/ls). For me, I could see that I have a directory named universal-darwin22 and none named universal-darwin21 as mentioned in the mkmf.log.
  4. Execute a command that creates a symbolic link named after the erroneous path used in the build script (e.g. /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin21 in my case), and symlink it to the correct path (in my case /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin22)
  5. Install ffi again and it should work. For me, I used this command: arch -x86_64 sudo gem install ffi

I hope this can help some people.

@chozandrias76
Copy link

I have a user who ran into this issue today on his Mac M1 based computer. The only steps that were required to fix this were running xcode-select --install and bundle install again.

@KrisLau
Copy link

KrisLau commented May 12, 2023

ok so i figured it out i had to do gem install cocoapods cause it wasn't detecting the brew installed one

@harisbaig100
Copy link

If you encounter the error "An error occurred while installing ffi (1.15.5), and Bundler cannot continue" while running the command npx react-native@latest init AwesomeProject, try initializing your project in a folder directory without spaces. For example, run npx react-native init on the "Desktop" directory, which usually doesn't have spaces in its path. This should resolve the issue.

@yusam123
Copy link

Here's what I did, this might help you @mareFernando03 :

  1. Open up the mkmf.log file mentioned in the output from the failed ffi installation. For me, this was at /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-21/2.6.0/ffi-1.15.5/mkmf.log.
  2. Look at the paths being referenced in the xcrun clang command, nearby the -I parameter. For me this is /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin21
  3. Navigate in Finder to the directory that is the parent of the universal-darwinXX directory to see what files you have in there (or cd/ls). For me, I could see that I have a directory named universal-darwin22 and none named universal-darwin21 as mentioned in the mkmf.log.
  4. Execute a command that creates a symbolic link named after the erroneous path used in the build script (e.g. /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin21 in my case), and symlink it to the correct path (in my case /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin22)
  5. Install ffi again and it should work. For me, I used this command: arch -x86_64 sudo gem install ffi

I hope this can help some people.

This work on my 2015 mac pro

@mrsantran
Copy link

mrsantran commented Jul 22, 2023

Mac M1 you need run this command:

sudo arch -arm64 gem install ffi

@AbeerAhmad
Copy link

check if there is any space in you root folder name or the folder its inside , remove that space and try again

@silaspedrosa
Copy link

silaspedrosa commented Sep 20, 2023

If you encounter the error "An error occurred while installing ffi (1.15.5), and Bundler cannot continue" while running the command npx react-native@latest init AwesomeProject, try initializing your project in a folder directory without spaces. For example, run npx react-native init on the "Desktop" directory, which usually doesn't have spaces in its path. This should resolve the issue.

In my case, the path didn't have any spaces, I just had to run xcode-select --install

However, if you encounter a message like this:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

try checking if there aren't any available updates to it in the System Settings.

If you do install updates, please restart your computer.

@dhirajhimani
Copy link

#937 (comment)

This works, I got confused on last 4th point, so adding it

sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin23 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin22

@lanrehnics
Copy link

lanrehnics commented Sep 26, 2023

#937 (comment)

This works, I got confused on last 4th point, so adding it

sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin23 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin22

You might get Operation not permitted using this, it's best to use

sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin23 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin22

@durga-nannamsetty
Copy link

@lanrehnics, you are right. I also got Operation not permitted error. Then I used your command and it executed without any error. After that I used sudo gem install ffi But I'm still getting the same ffi installation error.
May I know what is the command you used after creating a symbolic link?

@lanrehnics
Copy link

lanrehnics commented Sep 26, 2023

@lanrehnics, you are right. I also got Operation not permitted error. Then I used your command and it executed without any error. After that I used sudo gem install ffi But I'm still getting the same ffi installation error. May I know what is the command you used after creating a symbolic link?

Disclaimer !! You have to be careful with the next decisions

I was actually getting an error even after doing that, then I had to install another version of ruby using home brew.

brew install ruby

For M1, M2

echo 'export PATH="/opt/homebrew/opt/ruby/bin:/opt/homebrew/lib/ruby/gems/3.2.0/bin:$PATH"' >> ~/.zshrc

For Intel

echo 'export PATH="/usr/local/opt/ruby/bin:/usr/local/lib/ruby/gems/3.2.0/bin:$PATH"' >> ~/.zshrc

The 3.2.0 in the command above assumes Homebrew installed a Ruby version that starts with 3.2. If it installed a different version, replace 3.2 with the first two digits of your Ruby version.

Then "refresh" your shell for these changes to take effect:

source ~/.zshrc

Or you can open a new terminal tab, or quit and restart Terminal.

Replace .zshrc with .bash_profile if you are using Bash. If you're not sure, read my guide to find out which shell you're using.

To check that you're now using the non-system version of Ruby, you can run the following commands:

which ruby

It should not be /usr/bin/ruby

ruby -v

It should be 3.2.+ or later.

Once you have this new version of Ruby installed, you can now install bundler (or any other gem):

I then install cocoa pod
sudo gem install cocoapods

and everything has been okay since then .

Source

@JDMathew
Copy link

Ran into this error again today, updating X-Code Command Line Tools by running xcode-select --install fixed my issue

@oke-yomi
Copy link

oke-yomi commented Oct 19, 2023

Ran into this same issue. Here's how I fixed mine.

  1. In your mkmf.log, you would find the universal-darwinxx file you should have. In my case, it was /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin21

  2. Run this command cd $(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 to confirm what files you currently have. I found that I had universal-darwin22

  3. After you have confirmed that you have a different file, run this command sudo ln -sf universal-darwin22 universal-darwin21. This command creates a symbolic link named universal-darwin21 that points to universal-darwin22.

This should fix the issue

@KatieHarris2397
Copy link

l]]

@staycreativedesign
Copy link

Mac M1 you need run this command:

sudo arch -arm64 gem install ffi

this actually works, but my question is arent we supposed to be using brew for all this? instead of system?

@burhanwakhid
Copy link

Mac M1 you need run this command:

sudo arch -arm64 gem install ffi

Thanks, this work fine for me

@Yandamuri
Copy link

xcode-select --install fixed issue. I am using Macbook Pro M1 and Xcode 15.0.1

@leoniralves
Copy link

@lanrehnics, you are right. I also got Operation not permitted error. Then I used your command and it executed without any error. After that I used sudo gem install ffi But I'm still getting the same ffi installation error. May I know what is the command you used after creating a symbolic link?

Disclaimer !! You have to be careful with the next decisions

I was actually getting an error even after doing that, then I had to install another version of ruby using home brew.

brew install ruby

For M1, M2

echo 'export PATH="/opt/homebrew/opt/ruby/bin:/opt/homebrew/lib/ruby/gems/3.2.0/bin:$PATH"' >> ~/.zshrc

For Intel

echo 'export PATH="/usr/local/opt/ruby/bin:/usr/local/lib/ruby/gems/3.2.0/bin:$PATH"' >> ~/.zshrc

The 3.2.0 in the command above assumes Homebrew installed a Ruby version that starts with 3.2. If it installed a different version, replace 3.2 with the first two digits of your Ruby version.

Then "refresh" your shell for these changes to take effect:

source ~/.zshrc

Or you can open a new terminal tab, or quit and restart Terminal.

Replace .zshrc with .bash_profile if you are using Bash. If you're not sure, read my guide to find out which shell you're using.

To check that you're now using the non-system version of Ruby, you can run the following commands:

which ruby

It should not be /usr/bin/ruby

ruby -v

It should be 3.2.+ or later.

Once you have this new version of Ruby installed, you can now install bundler (or any other gem):

I then install cocoa pod sudo gem install cocoapods

and everything has been okay since then .

Source

This worked for me.
The only difference was how I set the PATH in zshrc
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc

vishaltak pushed a commit to vishaltak/gitlab-development-kit that referenced this issue Apr 3, 2024
In a previous commit [1], we switched to using the built-in FFI
provided with the `ffi` Ruby gem to avoid problems with upgrades
to the system FFI breaking the gem. However, this doesn't always
work because the built-in FFI implementation doesn't always build
correctly, dependent on the system compiler. For example, many
M1 Macs with a recent XCode installation are seeing odd failures
since 2022 [2].

In this commit, the switch to use `--disable-system-ffi` is reveted;
however, we still won't be using the system FFI. Instead, we will
take advantage of the fact that we use a `Brewfile` and have
Homebrew install a stable `libffi` version for us.

[1] https://gitlab.com/gitlab-org/gitlab-development-kit/-/merge_requests/3061
[2] ffi/ffi#937
@mediafinger
Copy link

I tried removing whitespaces manually, but to no avail. This tip of @chrisvasselli fixed the issue for me:

brew uninstall --ignore-dependencies pkg-config
brew install pkg-config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests