Rubys Galore Until They’re Not

Prenez
Dartable
Published in
5 min readOct 14, 2023

--

Flutter Doctor leads me on a merry chase

Synopsis: flutter doctor found a mismatch between ruby that cocoapods was using, and the one flutter was using. Turned out cocopods had been installed with brew, and was using a ruby in the brew cellar; while the system had another ruby installed by RVM in .rvm, and the path in .zshrc pointed to that. Solution was to delete the brew-installed cocoapods and reinstall with gem. But there were some detours along the way…

I wanted to get Flutter running on my M1 machine…which in theory shouldn’t be a problem, since it’s been running on my M2 machine for about 8 months. Well…

Installing Flutter was straightforward. The issue was when I ran Flutter Doctor, and it reported that everything was fine except Cocoapods, apparently Cocoapods was using a different Ruby than Flutter.

Hmm. What was that all about.

So, awhile ago, probably two years ago, I installed Ruby 2.7.2 on this machine using RVM. Worked fine. Replaced the standard Ruby (as of Sonoma, it’s 2.6.0, don’t know what it was two OS versions ago.)

So Cocoapods, according to some blog, ran better with 2.7.8, or something. So I tried to install 2.7.8 with RVM and got a big fail. Same with 2.7.5. The make was broken.

So I tried rbenv, which failed with 2.7.8, same problem, but succeeded with 3.2.2. But I couldn’t get the system to use the right ruby.

I went to my .zshrc and found paths to .rvm, and added the recommended paths for .rbenv, shims and bin.

export PATH="$PATH:$HOME/.rbenv/shims"
export PATH="$PATH:$HOME/.rbenv/bin"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)"
eval "$(rbenv init - zsh)"

Still broken. This kind of error when I ran pod:

pod/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
from /usr/local/bin/pod:23:in `<main>'

(hmm 2.6, whats that all about…more on that…)

and this kind of error on an attempt to reinstall cocoapods:

sudo gem install cocoapods
Password:
ERROR: Loading command: install (LoadError)
cannot load such file -- openssl
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass
michaelisbell@michaels-Mini flutter %

this was the error on an attempted install of ruby:

ruby-2.7.8 - #extracting ruby-2.7.8 to /Users/michaelisbell/.rvm/src/ruby-2.7.8 - please wait
ruby-2.7.8 - #configuring - please wait
ruby-2.7.8 - #post-configuration - please wait
ruby-2.7.8 - #compiling - please wait
ruby-2.7.8 - #installing - please wait
Error running '__rvm_make install',
please read /Users/michaelisbell/.rvm/log/1697259638_ruby-2.7.8/install.log
There has been an error while running make install. Halting the installation.

I tried creating the default alias for 2.7.8, as recommended by RVM, and it switched the version, but now it was a broken un-made Ruby.

So anyway…around this time, 2 am, I said to hell with it and went to bed.

THIS IS HOW I FIXED IT:

When I got up in the morning, I deleted $HOME/.rvm and $HOME/.rbenv and whatever else I needed to delete to get rid of those rubies.

IMPORTANT. I also went in and removed all .rvm and .rbenv lines from the .zshrc.

I did a ruby — version, and I was back to 2.6. ‘which ruby’ and ‘ruby — version’ verified that.

So now I installed cocopods with brew, and cocopods installed and ran correctly, so that was fixed. I noticed cocopods was pulling down ruby 3.2.2 inside brew, and sure enough ruby 3.2.2 was in the brew cellar.

Then I tried installing 3.2.2 with rbenv, and it worked, and had switched default ruby for my Mac in general to 3.2.2. I mean, outside the brew environment.

I also made sure to go back to my .zshrc, and re-added the recommended paths for .rbenv, shims and bin.

As an experiment, I tried uninstalling cocoapods and tried installing cocoapods againg with a gem install. It broke, so I quickly retreated to the former brew install of cocoapods.

So now I had working ruby, working cocoapods, working gem and flutter doctor was happy.

Next I tried creating ‘flutter create hello_world’’ and it ran but I got a security error on idevicesyslog — system didn’t know it, only gave me the chance to delete it.

I found out this is a Gatekeeper issue and needs these commands:

    sudo xattr -d com.apple.quarantine "Flutter_Path/bin/cache/dart-sdk/bin/dart"# idevice_id  
sudo xattr -d com.apple.quarantine "Flutter_Path/bin/cache/artifacts/libimobiledevice/idevice_id"# ideviceinfo
sudo xattr -d com.apple.quarantine "Flutter_Path/bin/cache/artifacts/libimobiledevice/ideviceinfo"# idevicename
sudo xattr -d com.apple.quarantine "Flutter_Path/bin/cache/artifacts/libimobiledevice/idevicename"# idevicescreenshot
sudo xattr -d com.apple.quarantine "Flutter_Path/bin/cache/artifacts/libimobiledevice/idevicescreenshot"# idevicesyslog
sudo xattr -d com.apple.quarantine "Flutter_Path/bin/cache/artifacts/libimobiledevice/idevicesyslog"

…and once that was done (and once I’d specified the Team in the Xcode project), then the demo flutter app ran fine on my phone.

So now I have 3 rubys on the system — 2.6 (the macos framework) — 3.2.2 installed by rbenv, and 3.2.2_1 installed by brew.

/opt/homebrew/Cellar/ruby/3.2.2_1
/Users/myname/.rbenv/versions/3.2.2
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin

Because I installed cocoapods using brew, it’s using the cellar version. because I installed flutter NOT using brew, it’s using the rbenv version (because of paths in .zshrc).

It’s been recommended I NOT mix brew and rbenv, and that I try chruby again (it broke like everything else last night, probably for the same frelled up config reasons). So I’ll have to resolve the Ruby In Two Places issue at some point, but not today.

LATER THAT SAME HOUR

So it turns out we did wrap it up today. I turns out the problem with the gem install of cocoapods was an issue with a package called activesupport that’s part of ruby on rails. Cocoapods breaks on v 7.1.1, so you have to uninstall it and install v 7.0.8.

Be aware you can have multiple versions installed, so when you uninstall activesupport, make sure you’re uninstalling 7.1.x, and only leave the one that works with cocoapods installed.

gem uninstall activesupport 7.1.1
gem install activesupport -v 7.0.8

then Pods will run as it should, and now cocoapods and flutter are using the same ruby, as the Muses intended. I uninstalled cocoapods and ruby from brew:

brew uninstall cocoapods
brew uninstall ruby

Now only two rubies on my system, in .rbenv and in MacOS frameworks. Nice and tidy.

NOTE I ended up using rbenv here, which I’ve never used before, but don’t like it that much. I may make another move towards chruby, which seems to be favored these days. I like the syntax better.

thanks to Zev Eisenberg and James Hughes for help on the iOS Folks Slack forum.

--

--

Prenez
Dartable

Writes iOS apps in Swift and stories in American English.