Christopher Oezbek
Christopher Oezbek

Reputation: 26353

Pretend other platform for `bundle install`

I am developing with bundler under Windows and am wondering how to create the Gemfile.lock for my production environment.

What seems missing are the gems for other platforms. Running bundle install on

group :production do  
  gem 'mysql2'
end

on Windows creates a Gemfile.lock

mysql2 (0.3.18-x86-mingw32)

When deploying to a Linux environment this is obviously not correct, I would need the Gemfile.lock to also contain the correct result for Linux. I can run bundle install on Linux and learn that indeed

mysql2 (0.3.18)

is the correct gem for Linux. I then manually update the Gemfile.lock in the repository to contain both:

mysql2 (0.3.18)
mysql2 (0.3.18-x86-mingw32)

This works clean under both platforms, but it seems a kludge.

How can I tell bundle to resolve the Gemfile.lock for another platform other than the local one? I guess I need something like bundle install --all-platforms. What am I missing?

Upvotes: 4

Views: 5048

Answers (2)

Ryan Lyu
Ryan Lyu

Reputation: 5125

Running the following commands will fix your issue.

bundle lock --add-platform x86_64-linux
bundle install
git add . ; git commit -m fix

Reference

  1. https://www.moncefbelyamani.com/understanding-the-gemfile-lock-file/#platforms

  2. https://bundler.io/man/gemfile.5.html#PLATFORMS

  3. https://github.com/rubygems/rubygems/issues/4269#issuecomment-758564690

Upvotes: 5

hd1
hd1

Reputation: 34657

It would appear this is a known shortcoming in bundler and the workaround seems to be to run bundle pack on every platform you need to use.

Upvotes: 2

Related Questions