问题
After running various commands (bundle and rspec for example) in a Ruby project, Gemfile.lock
is updated and x86_64-darwin-17
is added to the PLATFORMS
heading. Why is this happening? How can I prevent it?
Running gem env
gives this interesting context:
○ → gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.7.6
- RUBY VERSION: 2.5.1 (2018-03-29 patchlevel 57) [x86_64-darwin17]
#...etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-17
回答1:
This was caused by global bundler config. Setting to false stopped the behavior.
specific_platform (BUNDLE_SPECIFIC_PLATFORM): Allow bundler to resolve for the specific running platform and store it in the lockfile, instead of only using a generic platform. A specific platform is the exact platform triple reported by Gem::Platform.local, such as x86_64-darwin-16 or universal-java-1.8. On the other hand, generic platforms are those such as ruby, mswin, or java. In this example, x86_64-darwin-16 would map to ruby and universal-java-1.8 to java.
回答2:
The answer from @RangerRanger didn't work for me but I checked in the bundler doc as he did and find this who worked for me:
force_ruby_platform (BUNDLE_FORCE_RUBY_PLATFORM): Ignore the current machine's platform and install only ruby platform gems. As a result, gems with native extensions will be compiled from source.
Here is the command: bundle config force_ruby_platform true
回答3:
If you want to install dependencies without updating the Gemfile.lock
, just use the --frozen option. e.g. bundle --frozen
. This will install dependencies normally, except not update the Gemfile.lock
Edit
If this is not a good solution, probably the best bet is going to be adding the Gemfile.lock
to a .gitignore
specific to your local repo.
You can create one at your_repo/.git/info/exclude
as per this answer
来源:https://stackoverflow.com/questions/50765393/running-bundle-or-rspec-adds-line-to-gemfile-lock