Alexander
Alexander

Reputation: 4237

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?

Upvotes: 3

Views: 922

Answers (2)

nitsujri
nitsujri

Reputation: 1591

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

Upvotes: 3

eux
eux

Reputation: 3282

I tested on my Mac: macOS 10.15.7, Ruby 2.7.2, bundler 2.1.4

# Gemfile
gem 'grpc'

# Gemfile.lock
grpc (1.35.0)
      google-protobuf (~> 3.14)
      googleapis-common-protos-types (~> 1.0)

# bundle install log
Fetching grpc 1.35.0 (universal-darwin)
Installing grpc 1.35.0 (universal-darwin)

I don't have grpc (1.35.0-universal-darwin) in generated Gemfile.lock.

From the install log, my version of bundler will select proper version based on OS version, so you can't control it from Gemfile.

So few possible solutions are:

  1. Your colleagues who use Mac could try update bundler if they use older version of bundler.

  2. Remove grpc (1.35.0-universal-darwin) related code from Gemfile.lock, and tell your colleagues who use Mac don't commit that to git again (If solution 1 doesn't work).

Upvotes: 1

Related Questions