Work with Gems - how to update

In the first part, we saw some guidelines for choosing a Gem,  in the following post we will discuss updating gems which is an important use case for real world applications.

When to update?

Most of the available Gems in the ecosystem will receive some patches and updates. So we should check our installed versions for security fixes and performance improvement.

We can some online services like Gemnasium to scan your Gemfile and return which ones need to be updated.

How to update?

We need to remember that we should upgrade Gems separately one by one. I know it may take some time but you will avoid breaking your application and spending extra hours on weird bugs.

1. Read the changelog

It’s important to read about the changes and avoid selecting a version that introduces backward incompatible API.

2. Update

Just indicate in the Gemfile the specific version to update to and run bundler update command with the gem name like so:

#Gemfile
gem 'abc', '3.3.0'

#command
bundle update abc

3. Run tests

This is the verification part, we must check that the update didn’t break our application.

4. Repeat

We repeat the process for the remaining gems and that’s a typical workflow for keeping your application dependencies updated.

That’s it, happy coding 🙂