Can I stop Bundler from adding RUBY VERSION to Gemfile.lock
I don't think so, but maybe it's okay:
As of 2.1.0, Ruby no longer has multiple patch level releases for a given version. See accepted answer on How do version numbers work for MRI Ruby?
2.2.2p95 is the only patch level of 2.2.2 that will ever be released. 'p95' just means that there have been 95 commits since 2.2.0.
Since your whole team will be on 2.2.2 anyway, it shouldn't cause problems to leave this in your Gemfile.lock. (As long as everyone updates Bundler to the version that does this, anyway. Otherwise there'll still be conflicts as the ruby version is added and removed.)
Bundler is removing RUBY VERSION from Gemfile.lock
After a couple of days I stumbled upon another problem where I had to run spring stop
. After that it started to generate it correctly.
My bad for suspending my pc and have running those processes for weeks instead of trying the good old shutdown.
How to stop rails from adding BUNDLED WITH to the Gemfile.lock
After digging around a bit, and looking through those issues and comments shared by Jorge, you really only have two options:
- Downgrade your version of bundler to something earlier than 1.10
Ask your whole team to update their versions of bundler to something later than 1.10
gem uninstall bundler
gem install bundler -v 1.9.9
But as long as the downgrade doesn't cause any issues, it should be fine.
The developers for the bundler gem are not going to make any changes to the gem that will eliminate this problem. They're reasoning is that eventually everyone will be upgraded to something after 1.10.
Bundler: You must use Bundler 2 or greater with this lockfile
I deleted the project and made a git clone from the Heroku app, don´t know if it is a good solution, but it worked for me.
Ruby Bundler. How do I lock down all versions in Gemfile with working set from Gemfile.lock?
If you are trying to reproduce your current Gemfile.lock
in the Gemfile
for another project, you can specify the exact version of your gems.
Let's assume that I have the following Gemfile
in my Rails App:
source 'https://rubygems.org'
gem 'pg', '~> 0.18'
gem 'puma', '~> 3.0'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
It generates the following Gemfile.lock
:
GEM
remote: https://rubygems.org/
specs:
pg (0.21.0)
puma (3.10.0)
rails (5.0.5)
actioncable (= 5.0.5)
actionmailer (= 5.0.5)
actionpack (= 5.0.5)
actionview (= 5.0.5)
activejob (= 5.0.5)
activemodel (= 5.0.5)
activerecord (= 5.0.5)
activesupport (= 5.0.5)
bundler (>= 1.3.0)
railties (= 5.0.5)
sprockets-rails (>= 2.0.0)
If I want to reproduce exactly the same situation in a new project, I will create a Gemfile with exact versions:
source 'https://rubygems.org'
gem 'pg', '0.21.0'
gem 'puma', '3.10.0'
gem 'rails', '5.0.5'
and so on..
You can refer to bundler documentation
Edit
After you changed the focus of your question, it seems you are trying to create a Gemfile
from a Gemfile.lock
.
You could have a look at bundle --deployment. I saw several SO questions complaining about the output.
So, if it is not 100% satisfactory, you can use the Bundler::LockfileParser
and make your own script such as:
# test.rb
require 'bundler'
lockfile = Bundler::LockfileParser.new(Bundler.read_file('Gemfile.lock'))
specs = lockfile.specs
gems_hash = Hash.new.tap do |h|
specs.each do |s|
h[s.name] = {
spec: s,
dependencies: s.dependencies.map(&:name)
}
end
end
dependencies = gems_hash.keys && gems_hash.values.map { |h| h[:dependencies] }.flatten.uniq.sort
# Remove from the new Gemfile all gems installed as dependencies
dependencies.each { |dep| gems_hash.delete(dep) }
relevant_specs = gems_hash.values.map { |h| h[:spec] }
# I assume that by default you are installing from rubygems
puts "source 'https://rubygems.org'"
puts
relevant_specs.each do |s|
if s.source.to_s =~ /https:\/\/rubygems.org/
puts "gem '#{s.name}', '#{s.version}'" # eventually add "plaftform: :#{s.platform}"
# I consider as only alternative a git source.
elsif s.source.is_a?(Bundler::Source::Git)
uri = s.source.uri
branch = s.source.branch
ref = s.source.ref
puts
puts "git '#{uri}', branch: '#{branch}', ref: :#{ref} do"
puts " gem '#{s.name}'"
puts "end"
puts
end
end
puts
I created this gist for reading easily.
You can create then your Gemfile
by running:
$ ruby test.rb > Gemfile
bundle install does not respect Gemfile.lock
First of all it'll be great if you shared the Gemfile.lock error so as to know what i particular might be causing that upgrade. But from afar I think as you said this gem is a dependency gem and it is not stated in your gemfile. It could be that another gem also depends on this gem and per that requirement it triggers an upgrade even before your supposed gem line is run which may be leading to the error. Read the error thoroughly and you can identify the gem(s) causing this.
After your update I have read around on this.
Exactly so as stated earlier on, one of these gems could be the reason why your particular gem gets updated with every bundler install. Unfortunately there is no true turn around to solving this but bundler does give a way around.
You can use the --frozen option with bundler which freezes your gemfile.lock to the current versions for each gem and does not update any gem but only installs new gems that you have. Unfortunately this has been deprecated and can only be done be done from /.bundle/config. This can be done from the command line in the root of your project.
runbundle config frozen true
to freeze bundler from updating your gems in gemfile.lock
You may have to grant write permissions to your user to be able to edit the bundle configurations.
I found this article as well from bigbinary.com
Related Topics
Getting a Rogue Iteration from My .Each Loop
Config Undefined in Environment Specific Configuration Files
Ruby: Why Are All Coordinates Getting Updated in an Array of Arrays
Has_Many and No Method Error Issue
Accessing a Ruby Hash with a Variable as the Key
Why Should You Avoid the Then Keyword in Ruby
Ssl_Connect Syscall Returned=5 Errno=0 State=Sslv3 Read Server Hello a (Openssl::Ssl::Sslerror)
Jekyll:New Posts Not Being Generated
How to Find the Most Recently Modified Folder in a Directory Using Ruby
Hardcoded "Require 'Debug'" Can't Find the Sourcefile
How Does This Block Work for Integer Times Method
Rails, Ruby, How to Count and Sort, Display Top Results
How to Send Custom Invitation Using Devise_Invitable
Rails 6: Only One Profile Per User Should Be Created
How to Get the File Creation Time in Ruby on Windows
Dangerousattributeerror in Omniauth Railscast Tutorial: Create Is Defined by Activerecord
How Can Same Program in Ruby Accept Input from User as Well as Command Line Arguments