Ruby and Gem Installation Errors That Ruby on Mac Can Resolve

Published by Moncef Belyamani on

Every day, hundreds of people struggle to install Ruby or a particular Ruby gem on macOS. This happens frequently because there are many factors that can affect Ruby installation on a Mac. Here are a few of them:

  • The version of Xcode/Command Line Tools that’s currently installed
  • macOS version
  • Intel vs Apple Silicon
  • Installing things with and without Rosetta at the same time on an Apple Silicon Mac
  • The Ruby version you’re trying to install
  • The current active Ruby version
  • The version manager used (asdf, chruby, frum, rbenv, ruby-install, rvm)
  • Which OpenSSL versions are installed and which one you’re trying to compile with
  • Missing, misconfigured, and outdated dev tools
  • PATH issues
  • Setting ENV vars and other compilation settings globally in your shell startup file (.zshrc, .zprofile, .zlogin, .bash_profile, .bashrc, .profile, etc.)
  • The combination of things you installed so far, and the order in which you installed them

The good news is that Ruby on Mac can handle most of these common issues. When you run it in “normal” mode, it will automatically detect and fix any issues that it can resolve. In some cases, that’s not enough, which is why there’s also a “reset” mode. It will safely back up your dev setup, then clean it up in 1 minute. And then you can run it in “normal” mode to reinstall everything successfully in 15 minutes or less.

If you prefer to spend an hour or more doing everything manually, you can follow my free step-by-step guide for installing Ruby on a Mac. The guide works best when you start with a clean development environment, so you might need to spend an additional hour or more uninstalling all dev tools, or backing up your computer, reformatting the hard drive, and reinstalling macOS.

In general, if Ruby installation fails on your Mac, it’s most likely because your dev setup is not properly configured, or because the version manager you’re using expects you to specify certain settings depending on the version you’re trying to install. Some version managers are more helpful and reliable than others.

With Ruby on Mac Ultimate, you don’t have to worry about any of this. It sets everything up for you automatically, it installs the latest Ruby (currently 3.2.2) and 3.1.4 for you, and any other version you want to install is as easy as running rom install ruby 2.7.8 for example.

Common errors that can cause Ruby or gem installation to fail on Mac

Although Ruby on Mac can resolve pretty much any Ruby installation failure, I thought I’d list some specific error messages in case you’re wondering if the one you’re seeing can be handled by Ruby on Mac. If you’re getting an error that you don’t see listed here, feel free to contact me via any of the options listed at the bottom of this page, and I’ll let you know if Ruby on Mac can fix it.

configure: error: cannot run C compiled programs

Here’s an example of the last few lines of the error:

checking for llvm-strip... no
checking for gcc... clang
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... configure: error: in
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
make: *** No targets specified and no makefile found.  Stop.

This can be caused by outdated tools, which is why the first thing I recommend is to make sure Homebrew is up to date and that it’s not reporting any warnings or errors:

brew update
brew doctor

Also, make sure your macOS software is up to date, especially the Xcode command line tools. You can check for updates by clicking the Apple icon in the top left of your screen, then System Settings (or System Preferences in older macOS versions) and then click on or search for Software Update.

Error running ‘__rvm_make -j8’

There are variations of this error, with a different number after the -j. The number has nothing to do with the error. The number represents how many cores your Mac has. More powerful Macs will have a higher number. The more cores that are used, the faster the Ruby installation can run.

As mentioned at the beginning of this article, there are many factors that can cause Ruby installation to fail, and the version manager you use is one of them. In my experience testing all the version managers using dozens of real-world scenarios, rvm is one of the least reliable.

So, if you’re trying to install Ruby with rvm, try another version manager, such as ruby-install, rbenv, or asdf. But first, you have to disable RVM because version managers are not compatible with one another. Check the RVM documentation for how to get rid of it, but I think rvm implode should take care of most of it.

Compiling Ruby 3.1.4 failed

This error usually appears when installing Ruby with ruby-install, and has exclamation marks before and after the message, such as:

!!! Compiling ruby 3.1.4 failed!

The Ruby version mentioned in the error will depend on the one you’re trying to install. In general, these are due to outdated, missing, or misconfigured dev tools, or the way ruby-install is configuring the Ruby compilation.

Here’s an example error due to OpenSSL issues:

./openssl_missing.h:215:46: note: expanded from macro 'TS_VERIFY_CTX_set_certs'
#  define TS_VERIFY_CTX_set_certs(ctx, crts) TS_VERIFY_CTS_set_certs(ctx, crts)
                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./openssl_missing.h:195:52: note: expanded from macro 'TS_VERIFY_CTS_set_certs'
#  define TS_VERIFY_CTS_set_certs(ctx, crts) ((ctx)->certs=(crts))
                                              ~~~~~^
/opt/homebrew/Cellar/openssl@3/3.1.3/include/openssl/ts.h:407:16: note: forward declaration of 'struct TS_verify_ctx'
typedef struct TS_verify_ctx TS_VERIFY_CTX;
               ^
1 warning and 1 error generated.
make[2]: *** [ossl_ts.o] Error 1
make[1]: *** [ext/openssl/all] Error 2
make: *** [build-ext] Error 2
!!! Compiling ruby 3.1.4 failed!

undefined method `deprecator’ for ActiveSupport:Module (NoMethodError)

This is a recent bug with Cocoapods caused by the latest version of the activesupport gem, which Cocoapods depends on. It has been fixed in this pull request, but the Cocoapods team hasn’t released a new version yet. Apparently, it takes them months sometimes to release a new version.

The good news is that Ruby on Mac can automatically install Cocoapods for you in a way that bypasses this issue. However, for projects that use Cocoapods via a Gemfile, you might still need to pin activesupport to version 7.0.8 until Cocoapods releases a new version with the fix. You can do that by running this command from the directory that contains your Gemfile:

bundle add activesupport -v 7.0.8
bundle install

This assumes that you already have a proper Ruby development environment, like the one Ruby on Mac sets up for you. When you have a proper Ruby dev setup, you should be able to install the Cocoapods gem without using sudo.

Unfortunately, the official instructions on the Cocoapods website are not the ones I would recommend. I’m surprised that they recommend using sudo because it’s dangerous and can lead to all kinds of issues. Learn why would should never use sudo to install gems.

They also recommend using the standard Ruby available on macOS instead of a version manager, which is also the complete opposite of what I would recommend, especially for people new to Ruby. Here are 5 reasons why you shouldn’t use the system Ruby. And I’m not the only one to warn about this. Check out the Don’t Use System Ruby site as well.

The good news is that Ruby on Mac can automatically and properly install Cocoapods for you so you can use it right away, whether you’re using it with Flutter, React Native, Unity, or any other project that needs it.

Here is a more complete error message you might see when you don’t have Cocoapods configured properly:

/Users/moncef/.gem/ruby/3.2.2/gems/activesupport-7.1.1/lib/active_support/core_ext/array/conversions.rb:108:in `<class:Array>': undefined method `deprecator' for ActiveSupport:Module (NoMethodError)

  deprecate to_default_s: :to_s, deprecator: ActiveSupport.deprecator
                                                          ^^^^^^^^^^^
Did you mean?  deprecate_constant
  from /Users/moncef/.gem/ruby/3.2.2/gems/activesupport-7.1.1/lib/active_support/core_ext/array/conversions.rb:8:in `<top (required)>'
  from <internal:/Users/moncef/.rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
  from <internal:/Users/moncef/.rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
  from /Users/moncef/.gem/ruby/3.2.2/gems/cocoapods-1.13.0/lib/cocoapods.rb:9:in `<top (required)>'
  from <internal:/Users/moncef/.rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
  from <internal:/Users/moncef/.rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
  from /Users/moncef/.gem/ruby/3.2.2/gems/cocoapods-1.13.0/bin/pod:36:in `<top (required)>'
  from /Users/moncef/.gem/ruby/3.2.2/bin/pod:25:in `load'
  from /Users/moncef/.gem/ruby/3.2.2/bin/pod:25:in `<main>'

CocoaPods installed but not working

You might get this error when running flutter doctor. It might say something like this:

✗ 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.
To re-install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.

As in the previous example, this is due to Cocoapods not being installed properly, or having multiple Cocoapods installations. For example, with both Homebrew and via gem install cocoapods.

Again, Ruby on Mac is the easiest way to get out of this mess. It will automatically detect and clean up a broken Cocoapods setup, and will fix it for you.