How to stop rails from adding BUNDLED WITH to the Gemfile.lock - ruby-on-rails

I'm working with a distributed team of developers and I'm getting this issue of having to commit the Gemfile.lock with bundled with info added to the bottom:
BUNDLED WITH
1.10.2
We're obviously using different versions of things, ie rvm/rbenv, and I'm wondering if there's a way to stop my system doing this.
Bundler version 1.10.2 (obviously)

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.

Locate the file lib/bundler/definition.rb in your local installation of the bundler gem (you can use gem env to locate the folder where your gems are installed) and remove these three lines
# Record the version of Bundler that was used to create the lockfile
out << "\nBUNDLED WITH\n"
out << " #{lock_version}\n"
You might need to restart spring after the change

Related

In a Ruby on Rails installation, what is causing webrick to be outdated and why `gem i webrick` can update it?

I have a new Mac computer and installed rails on it, and then I tried out the command
gem outdated
for some reason, it showed one of the gems outdated:
webrick (1.4.2 < 1.6.0)
I wonder why it is outdated on the first installed, and when I did
sudo gem install webrick
it actually installed 1.6.0 onto the system. Doesn't it require gem update instead of install to update something? How come install also updated it?
Not exactly, gem install GEM_NAME will install the last version available if you don't specify a version when installing, and you can have more than 1 version of the same gem on your machine.
you can run gem environment, and check where gems are installed, go to that folder and you will see both version gems folder there.
so when you create a rails project for example and add a specific version of a gem in the gemfile and another version on another project, you can have both without problems

How do I delete gems for old ruby versions installed by bundler?

I want to free up disk space in my production environment taken up by gems installed for old ruby versions. I don't believe bundle clean will work in this instance, because I don't think it cleans out the old gems for other rubies.
These gems are installed via capistrano and are installed in a custom location, rather than system wide. In my /path/to/my-project/shared/bundle/ruby dir, I see 2 subdirs - 2.2.0 & 2.3.0. Since I am now using ruby 2.3, is it safe just to delete the 2.2.0 directory? Is there anything else I need to do?
Use "sudo gem cleanup" to remove all previously installed gems which respecting all the dependencies be it on old version of ruby. You can see all the gems that ll be removed with command "sudo gem cleanup -d"
here is how you can remove a specific version of the gem:
gem uninstall (gem name here) --version (version number here)
Go to Gemfile.lock and delete all its content. Then you go to Gemfile and delete gems you do not want anymore. After, You type bundle install and it will install just the ones you want.

How to run a specific version of a ruby gem

I am running brakeman outside of my Gemfile, so am not using bundler.
If I do gem list, I can see I have the following for brakeman
brakeman (3.3.3, 3.3.2, 3.1.4, 3.1.2)
But if I do brakeman --version, I get
brakeman 3.1.2
so I am not using the latest version. If I do gem update brakeman or
gem update brakeman, '3.3.3,
I get
Updating installed gems
Nothing to update
So how do I run brakeman version 3.3.3?
If you have several gem versions installed and you want to invoke a specific version from the command-line, you could use:
brakeman _3.3.3_ [args go here]
This is not specific to brakeman, you can do this for most other gems as well.
I can't reproduce this issue, but I can think of a few reasons why this might happen:
Bundler artifacts (perhaps in .bundle/) pointing to the old version. Try running in a different directory and see if it still happens
A bug in RubyGems (try gem update --system)
During install, it asked if you wanted to replace the brakeman binary and you selected "no"
If you are using a Ruby version manager, maybe one version is on a different path than another (like a system gem versus one managed by rvm)
Any number of GEM_PATH, bundler, gem, rvm weirdness that sometimes occurs
In any case, if I were you I'd gem uninstall brakeman, remove all versions, and install fresh. If you are using rvm, start with a fresh gemset or rvm gemset empty the current one.
I had a similar problem: I uninstalled a certain gem version, but the version still showed up.
TL;DR: rbenv rehash did the trick. (Only valid for rbenv users, obviously)

How can I find out what gem is dependent on termios in my Gemfile?

I have updated all of my gems, including to Rails 3.2.8, prior to a new deployment. However, my application is now broken because something is trying to install gem "termios" version 0.9.4.
Apparently, 0.9.4 does not work on any computer or server I own. There are some newer versions, 0.9.6 specifically, but they are not posted in wherever bundler looks for gems.
There are some version on Github, but they have been mysteriously renamed "ruby-termios". Well, some gem in my Gemfile is not looking for ruby-termios. It's looking for termios. Failure.
How can I find out which gem is trying to install this so I can see if it can be whacked?
Check your Gemfile.lock - it has all the gems and their dependencies listed in it. As long as you've been able to install these gems in the past, you'll be able to tell where that dependency is coming from.
The gem command will dump out the tree of dependencies for you.
$ gem dependency
Or if you want to check just a specific gem.
$ gem dependency foo

What is the difference between Gemfile and Gemfile.lock in Ruby on Rails

I am a beginner to Ruby on Rails and I am using Rails 3.0.9.
What is the difference between Gemfile and Gemfile.lock in Rails?
The Gemfile is where you specify which gems you want to use, and lets you specify which versions.
The Gemfile.lock file is where Bundler records the exact versions that were installed. This way, when the same library/project is loaded on another machine, running bundle install will look at the Gemfile.lock and install the exact same versions, rather than just using the Gemfile and installing the most recent versions. (Running different versions on different machines could lead to broken tests, etc.) You shouldn't ever have to directly edit the lock file.
Check out Bundler's Purpose and Rationale, specifically the Checking Your Code into Version Control section.
Usually we write dependencies in Gemfile as:
gem "nokogiri", "~> 1.4.4"
gem 'bcrypt-ruby', '~> 3.0.0'
gem 'uglifier', '>= 1.2.3'
..
Here you basically say: "I want nokogiri as long as it’s greater than version 1.4.4", etc. Now suppose that I have set up my Gemfile 8 months ago and I successful setup my app with this requirement. 8 months ago nokogiri version was 1.4.4. My rails apps was running perfectly without any problems with this version.
Now think I'm trying to build with the same Gemfile. But if we look at nokogiri versions we see that the current stable version has changed to 1.4.9. That means if we try to build, bundler will install version 1.4.9 of nokogiri (suppose we don't have Gemfile.lock).
What does it mean ?
As you see if you don't have any Gemfile.lock and run:
bundle install
then the currently used gems can be different at any time. Your app used the version 1.4.4 and it works 8 months ago without any problems, but if you try to build it now you get the version 1.4.9. Maybe it's broken with the latest version of nokogiri, the awesome feature you used with 1.4.4 is not more available, etc..
To prevent this kind of problem Gemfile.lock is used. In Gemfile.lock only the exact versions are written and thus only these will be installed. That means if you distribute your app with a Gemfile.lock, every machine will have the same gems installed and most important they all get the same version. This will give you a stable and common deployment stack.
How is Gemfile.lock created?
It is automatically created with the first:
bundle install
command. After that everytime you run bundle install, bundle will first look up Gemfile.lock and install the gems specified there. It's an habit to distribute this file among your projects to provide consistently and stability.
How to update Gemfile.lock?
If you're happy with the the latest version of your apps than you can update Gemfile.lock. Just reflect your changes to Gemfile. That means change the dependencies to the new exact versions in Gemfile. After that run:
bundle install
This will update you Gemfile.lock with your newest version of apps.
The Gemfile.lock
When you run bundle install, Bundler will persist the full names and versions of all gems that you used (including dependencies of the gems specified in the Gemfile(5)) into a file called Gemfile.lock.
Bundler uses this file in all subsequent calls to bundle install, which guarantees that you always use the same exact code, even as your application moves across machines.
Because of the way dependency resolution works, even a seemingly small change (for instance, an update to a point-release of a dependency of a gem in your Gemfile(5)) can result in radically different gems being needed to satisfy all dependencies.
As a result, you SHOULD check your Gemfile.lock into version control. If you do not, every machine that checks out your repository (including your production server) will resolve all dependencies again, which will result in different versions of third-party code being used if any of the gems in the Gemfile(5) or any of their dependencies have been updated.

Resources