Open In App

How to update gems with Bundler?

Last Updated : 02 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In the Ruby programming language, a gem is a package of code that can be installed and used in a Ruby project. Gems provide a convenient and standardized way to distribute and reuse code and are a key component of the Ruby ecosystem. Bundler is a package manager for Ruby that manages the gems and their dependencies in a Ruby project. Bundler provides a consistent and reliable way to install the gems that your project needs, and ensures that the correct versions of the gems and their dependencies are used in your project.

Steps to Update Gems with Bundler

Following are the steps to be followed in order to update gems with bundler,

Step 1: To update gems with Bundler, you can use the bundle update command. This command will update the gems in your Gemfile to the latest versions that are allowed by the version constraints specified in the Gemfile. For example, if your Gemfile looks like this,

updating-gems

 

Step 2: You can update the gems using the following command,

bundle update

bundle-update

 

This will update the rails and pg gems to the latest versions that are compatible with the version constraints specified in the Gemfile. In this case, the rails gem will be updated to the latest version in the 6.0.x series (e.g. 6.0.3.2), and the pg gem will be updated to the latest version that is greater than or equal to 1.2.0 (e.g. 1.2.3). The Sinatra gem will not be updated, because it does not have any version constraints specified in the Gemfile.

Step 3: You can also use the bundle update command with the name of a specific gem to update only that gem. For example, the following command will update only the rails gem,

bundle update rails

rails-gems-update

 

This will update the rails gem to the latest version that is allowed by the version constraint specified in the Gemfile (e.g. 6.0.3.2). The other gems in the Gemfile will not be updated.

Step 5: You can also use the bundle update –all option to update all the gems in the Gemfile, regardless of the version constraints specified in the Gemfile. This can be useful if you want to update all the gems to the latest versions, even if they may not be compatible with the version constraints in the Gemfile. For example:

bundle-update-all

 

This will update all the gems in the Gemfile to the latest versions available on RubyGems.org.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads