Gems for Rubys
Gems are Ruby's packaged libraries, and Bundler is the tool that installs and locks them for a project. A Gemfile lists dependencies, bundle install resolves versions into Gemfile.lock, and the same versions then load on every machine. Tools like RuboCop check style so a codebase stays consistent.
Stage: Tooling · Part of the Ruby roadmap · Last reviewed 19 November 2026
What to learn in Gems
- Install a gem and require it in a script
- Write a Gemfile and run bundle install
- Explain why Gemfile.lock should be committed
- Run code with bundle exec to use locked versions
- Lint and auto-correct style problems with RuboCop
Gems interview questions
What is the role of Gemfile.lock?
It records the exact versions of every gem Bundler resolved, including indirect dependencies. Committing it means all developers and servers install identical versions, avoiding bugs that appear only on one machine after a gem updates.
What does a pessimistic version constraint like ~> 2.1 mean?
It allows upgrades that stay within the specified precision. ~> 2.1 accepts 2.1 and any later 2.x release but not 3.0, while ~> 2.1.3 accepts 2.1.x from 2.1.3 up. It permits compatible updates and blocks likely breaking ones.
Where Gems fits in the Ruby roadmap
Gems belongs to the Tooling stage (beginner level), which takes about 12 hours. The ecosystem.