I know there are many instances of this question. I've done everything in those answers and have gotten nowhere after 4 hours.
I am trying to install a gem on Catalina 10.15.7 and getting the ever-popular
/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.
with this additional context
ERROR: Error installing ffi:
ERROR: Failed to build gem native extension.
current directory: /Users/bmanica/.chefdk/gem/ruby/2.4.0/gems/ffi-1.13.1/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 ./siteconf20200925-10024-qilctf.rb extconf.rb --with-cflags\=-save-temps\=obj\ -o\ tmp/a.o
when invoking the installation via
gem install ffi -- --with-cflags="-save-temps=obj -o tmp/a.o"
to get around Catalina's draconian permissions rules.
I've freshly downloaded XCode and the command line tools:
> xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
> xcode-select -p
/Applications/Xcode.app/Contents/Developer
> ls /Applications/Xcode.app/Contents/Developer
Applications Library Makefiles Platforms Toolchains Tools usr
I've accepted the license at least four times via
sudo xcodebuild -license accept
I've tried
sudo xcode-select -switch /
as Gem installation error: You have to install development tools first suggests. I am not on Windows so the rubyinstaller link does not help me.
Can't Find ffi.h When Installing ffi ruby gem references the exact gem I am trying to install, but as indicated xcode-select --install
is not the answer.
None of the answers in Developer tools issues when installing Ruby gems are helpful either; I have already brew install openssl
and brew install libffi
and have exported the variables it told me to:
> set | grep FLAGS
CPPFLAGS=-I/usr/local/opt/libffi/include
LDFLAGS=-L/usr/local/opt/libffi/lib
> set | grep PATH
PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig
I've also tried the suggestions in How to update Xcode from command line - xcode-select -r
does nothing, xcode-select -s /Library/Developer/CommandLineTools
does nothing, and $ sudo rm -rf /Library/Developer/CommandLineTools
prevents xcode-select --install
from working, and additionally I moved it anyway and redownloaded the command line dmg package from Apple's developer site. Still same problem.
What do I try next to get this gem to install?
Judging by the path names in your error message, you are trying to modify Apple's System Ruby. This is not allowed.
Apple's System Ruby is exclusively for internal use by macOS and/or support for legacy applications. You must not use it, and you most certainly must not modify it. Modifying it would negate the whole "support for legacy applications" thing.
Apple itself has the following to say in the release notes for macOS 10.15 Catalina:
There are many, many options for installing Ruby on macOS, including but not limited to compiling it yourself, downloading pre-compiled binaries, Homebrew, ruby-install, ruby-build, RVM. There are many options for managing Ruby installations on macOS, including but not limited to chruby, asdf, rbenv, and RVM.
Most of these have the added advantage that they support newer versions than the one Apple ships, and even more interesting, they support different implementations than just YARV. My personal favorite is TruffleRuby, which, when run on the GraalVM, was up to 1000 times faster for me, depending on the benchmark.
Please, do not use System Ruby.