Search code examples
ruby-on-railsrubygemsbundlergemfile

Rails: Handling different gem versions for different operating systems


My Rails 6 project uses some gems that install the grpc gem. In my Gemfile.lock, the gem is installed like this:

grpc (1.32.0)
  google-protobuf (~> 3.13)
  googleapis-common-protos-types (~> 1.0)

One of the people on the team has a Mac. When they run bundle install, it installs the OS X specific version of the gem in addition to the version above, so the Gemfile.lock will look like this:

grpc (1.32.0)
  google-protobuf (~> 3.13)
  googleapis-common-protos-types (~> 1.0)
grpc (1.32.0-universal-darwin)
  google-protobuf (~> 3.13)
  googleapis-common-protos-types (~> 1.0)

Other Gemfile information:

PLATFORMS
  ruby

RUBY VERSION
   ruby 2.5.7p206

BUNDLED WITH
   2.2.1

My local and production servers run Linux. When I attempt to run bundle install on my local environment with this in the Gemfile.lock, the bundle install exits with a Killed message, presumably because the gem is incompatible with my OS.

I've tried adding the gem to my Gemfile directly like this:

gem 'grpc', '1.32.0'

But that seems to only work sometimes, weirdly enough. How can I update the Gemfile to not install the OS X version of the gem and use the base version instead?


Solution

  • If anyone running into this. This was a known bug that was fixed in bundler version v2.2.11

    From: How to change the version of bundler used in Cloud Functions deployment?

    This is bundler's regression since bundler v2.2.8. https://github.com/rubygems/rubygems/issues/4366

    Fix is here: https://github.com/rubygems/rubygems/pull/3655