Solve Mac ruby issues in React native installations

Zameer
2 min readMar 5, 2023

--

On the latest 0.71 installation, React native documentation specifies:

“React Native uses a .ruby-version file to make sure that your version of Ruby is aligned with what is needed. Currently, macOS 13.2 is shipped with Ruby 2.6.10, which is not what is required by this version of React Native (2.7.6). Our suggestion is to install a Ruby version manager and to install the proper version of Ruby in your system.”

Like me, if you had gone ahead without heeding to such warnings, mostly out of sheer confidence of already knowing the drill, you will find yourself into problems like these at the installation:

  1. Your Ruby version is 2.6.8, but your Gemfile specified 2.7.6
  2. Ignoring ffi-1.15.0 because its extensions are not built.
  3. You don’t have write permissions for the /Library/ …

For 2nd Issue, the solutions are

sudo gem pristine ffi

and then,

gen install cocoapods

But, It will fail in error with either 1 or 3 above error message.

Bottom-line idea is that RN uses a new ruby version for cocoapods and it automatically gets the system ruby version. We cannot update the system ruby version (obviously? or else how would our favorite mac ruby apps run?).

So we need to use a package manager like NVM for node. So we have to use a package manager for ruby and set the default version to terminal when it opens. I tried but did not get any luck with Chruby. Following works with rbenv.

Now I’m neither a ruby developer nor using ruby for anything other than running cocoapods in my mac, so conflicts of different ruby versions or even the possibility of already installed ruby package managers was a null. There could be different reasons for the above errors, but this following is how I resolved it. This applies only for Intel Macs, if you are intuitive enough, God help you in your quest, I think you will find your way to install in M1 as well. It’s a journey.

Using rbenv,

Installation using HomeBrew (Install it if you haven’t already)

brew install rbenv ruby-build

Install ruby 2.7.6

rbenv install 2.7.6

Use 2.7.6 globally

rbenv global 2.7.6

In the .zhrc file (if you dont have it, you will need to create it in your home folder)

eval "$(rbenv init — zsh)"

Close the terminal and launch again and check your ruby version,

ruby -v

Now make sure you are using Node 18.0.0 (either installing it as standalone or use NVM to do it) and you should be able to proceed with the installation.

There seems to be a paid fix for all common ruby issues, if you ran into any issues from these steps or having a far more complex issue, you can try it out, But I feel like the script to manage the ruby on mac should be a no-brainer at best or a free open source script. I don’t know the M1 issues yet, if it’s far more troubling probably paying for it will save time, because these issues drain out our energy and time.

--

--