Updating a Rails Bundle Package - ruby-on-rails

I want to make a Rails Bundle Package for a client. I am using Rails 3.0.3 and Ruby 1.9.2. What is the process if I need to update the bundle package with new gem versions?

If you want to update to a specific version, use #Ferdy's answer, but if you just want to update to the most recent version run:
bundle update gem_name
This will update your gem to the latest version, and also update all of its dependencies. It will also update your Gemfile.lock file so that you can commit it to source code. Other systems will now just need to run:
bundle install
to get the update.

You want to update the gems used in a rails project? My guess is that you update the versions in the GemFile
gem 'name', 'version'
and then run bundle install.. This will install all the appropriate versions.

Related

Ruby: I cannot create gemfile.lock with default bundler version

I want to create my gemfile.lock file with bundler version 2.3.25
But when I try to bundle install it always is bundled with 2.4.5
So I uninstall bundler version 2.4.5 and it STILL bundles with that version, and then throws errors when I rails s because version 2.4.5 isn't there.
When I run gem list bundler right now I get: bundler (2.4.5, default: 2.3.25)
I've gone as far as to delete the file from
\\wsl$\Ubuntu\home\me\.rbenv\versions\2.7.0\lib\ruby\gems\2.7.0\gems\bundler-2.4.5
then, I delete the gemfile.lock file and bundle install and low and behold its bundled with 2.4.5..
I've tried gem uninstall bundler and no luck..
I've tried all of the following methods and no luck
Here
or
Here
How can I either force Ruby to use the default version of Bundler, or REALLY get rid of the version I don't want?
Bundler will add its version number to Gemfile.lock after you've run bundle install:
BUNDLED WITH
2.4.5
Therefore you can run bundle install with version 2.4.5 to generate Gemfile.lock and then edit it with a text editor to replace the version with the version you require. Then, when you run bundle install again bundler will notice that and will use the older version that you specify.
Gemfile.lock is a pretty straightforward and standard format and there are no material changes to it between those versions.
Otherwise, you can do like #engineersmnky said (and is explained in this other answer) and use:
bundle _2.3.25_ install

ROR - How to update a rubygem to a particular version?

I am trying to update a gem version to a particular version. But whenever I run command bundle update gem, it is updating the latest version of that gem.
Even on running command bundle update gem -v "x.x.x" it is still updating to the latest one.
Is there any way to update a gem version to a particular version?
In your Gemfile specify the gem version. For example:
gem "foo", "= 1.0.0"
then run bundle update foo

I want the latest version of Rails when creating a new app

The current official version of Rails is 4.0.3.
When I create a new Rails app I get version 4.0.2, and then I have to update the Gemfile and run bundle update.
What should I do to have the latest version of Rails (and all other default gems) on my system, such that when creating a new app it automatically has the latest version?
If you run gem update it will update all installed rubygems. This includes rails and all gems on your system.
You should be careful though since you may not want to update everything. In that case you can specify gems individually.
gem update rails
To get the latest gems you can run
gem update
To simply see what gems can be updated you can run
gem outdated
To update just the rails gem you can do
gem update rails

behavior of bundler in rails 3.2

when i run bundle install the first time this will create a gemfile.lock for me
after this my question is :
if i run bundle install for the second time what does bundler do ?
i think it look first at gemfile.lock and check each line, and then look in the gemfile and check gems that not exist in gemfile.lock then install them !!! i'm not sure , and i which if someone can explain that to me (step by step )
second question is :
for example i add a gem like this gem 'nokogiri', '~> 1.4.2' , suppose after 1 month, version 1.4.3 is available. i think it will be installed automatically if i run bundle install again ?
can this new version "with tiny update" break things in my app ?
The duty of Gemfile.lock is to lock the versions of the gems you use.
bundle install installs all gems in your Gemfile that are not in your bundle and records the version in Gemfile.lock.
bundle install only installs the versions of your gems, that are recorder in Gemfile.lock. It will never update any gem.
For updating gems, use bundle update. It looks for new versions of your gems, installs them and records the new versions in Gemfile.lock.
If you specify a version in your Gemfile like in your example
gem 'nokogiri', '~> 1.4.2'
bundle upate would only update nokogiri to revisions < 1.5
Any update (in fact any change) might break your application, but minor updates are supposed to be completely backward compatible (stable API, only new tests, all old test pass)
From the documentation,
(...) the first time you run bundle install (and a Gemfile.lock does not exist), bundler will fetch all remote sources, resolve dependencies and install all needed gems.
If a Gemfile.lock does exist, and you have not updated your Gemfile, bundler will fetch all remote sources, but use the dependencies specified in the Gemfile.lock instead of resolving dependencies.

When creating a new Rails application, why is there a Gemfile.lock file without running bundle install?

And, how does the system install all the gems for the application without going through the bundle install process?
Note: This question is about the process of creating a new application. Not the same question as In Rails, why there is a new Gemfile.lock when no bundle or bundle install was run? (and a new Gemfile timestamp too) .
Gemfile.lock is a snapshot of the gems and their versions created when you run bundle install. As explained in the Checking Your Code into Version Control section of the Bundler rationale:
Gemfile.lock makes your application a single package of both your own
code and the third-party code it ran the last time so you know for sure
that everything worked. Specifying exact versions of the third-party
code you depend on in your Gemfile would not provide the same
guarantee, because gems usually declare a range of versions for their
dependencies.
Gems can be installed outside of bundler by RubyGems (e.g. gem install gem_name) but it's best to use RVM which allows you to install separate versions of Ruby and manage individual gemsets for each application as explained in the RVM best practices.
When you do rails new <app>, as part of setup it runs bundle install for you.

Resources