10

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?

max
  • 96,212
  • 14
  • 104
  • 165
cbmanica
  • 3,502
  • 7
  • 36
  • 54
  • Accept the XCode license: `sudo xcodebuild -license accept`. Also, use a Ruby manager; do *not* install gems to your system Ruby. – Todd A. Jacobs Sep 25 '20 at 19:38
  • 1
    Sorry, meant to post I've accepted the license at least four times as well. – cbmanica Sep 25 '20 at 19:39
  • A little word of advice. Don't lead with "Yes, I have read the other questions just like this" instead just present what you have researched so far. A question that is this well written doesn't need it and it really just drags it down. – max Sep 27 '20 at 15:23
  • I ran into the same problem. I solved it like this https://stackoverflow.com/questions/66081684/installing-cocoapods-via-ruby-causes-error/66087099#66087099 – four-eyes Feb 07 '21 at 11:00

2 Answers2

13

Finally got it after hours. I followed this instruction, changed it a bit

  1. Make sure brew is installed. If not /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

  2. Set shell to zsh curl -L http://install.ohmyz.sh | sh

or, set PATH

  1. eval "$(rbenv init -)"

  2. Install Ruby Version Manager brew update brew install rbenv ruby-build

  3. Install Ruby rbenv install 2.6 # I used my systems default version number because I was not sure if it messes with my OS X system version. rbenv global 2.6 rbenv rehash

  4. Add it to your zsh echo 'eval "$(rbenv init -)"' >> ~/.zshrc source ~/.zshrc

That did it for me. All the other stuff like installing Xcode, accept the Xcode License, Xcode command line tools did not do it.

four-eyes
  • 10,740
  • 29
  • 111
  • 220
  • Thank you soooooooo much, that did the trick for me – Mebius Dec 16 '21 at 14:38
  • worked for me 2022 – EMT Oct 25 '22 at 10:01
  • Just logged in for the first time in years to tell you THANK YOU! I have spent the last 6 hours on this and my RAM is full of tabs with non-working solutions. The trick seems to be to execute the (rbenv init -) command so that the installer routine uses YOUR version of ruby (and the corresponding header files) – python00b Jun 01 '23 at 14:26
-2

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:

Scripting Language Runtimes

Deprecations

  • Scripting language runtimes such as Python, Ruby, and Perl are included in macOS for compatibility with legacy software. Future versions of macOS won’t include scripting language runtimes by default, and might require you to install additional packages. If your software depends on scripting languages, it’s recommended that you bundle the runtime within the app. (49764202)

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.

Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
  • I tried to get rbenv to work for an additional two hours after I posted the question, also doesn't work. I've given up, mind you. – cbmanica Sep 26 '20 at 14:15