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:
- Open the Gemfile.
- Specify the version number in front of the gem.
- 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
.