How to Update Ruby Gems

Nurudeen Ibrahim Feb 02, 2024
  1. Update a Ruby Gem to a Specific Version
  2. Upgrade a Ruby Gem to a Latest Version
How to Update Ruby Gems

Ruby Gems are open source libraries containing Ruby code and packed with some additional data. Rails is a Ruby language-based web application development framework.

Updating Ruby gems is a common task you have to do as a Ruby developer. Let’s briefly discuss how to update Ruby Gems on Rails.

Update a Ruby Gem to a Specific Version

The command below only updates the RubyGems software, not the installed gems.

Command:

gem update(--system)

To upgrade a gem to a specific version, re-install the gem and specify the version number.

Example Command:

gem install rails -v 6.0

Running the above code on my machine upgrades my Rails v5 to 6.0.

To upgrade a gem to a specific version for a Ruby application, do the following steps:

  1. Open the Gemfile.
  2. Specify the version number in front of the gem.
  3. Run bundle install.

Upgrade a Ruby Gem to a Latest Version

To upgrade a gem to the latest version, re-install the gem without specifying any version number.

Example Command:

gem install rails

Running the above code on my machine upgrades my Rails to v7.

To upgrade a gem to the latest version for a Ruby application, run bundle update gem-name.