Ruby Gems & Bundler Cheat Sheet
Covers RubyGems CLI commands, Gemfile syntax, Bundler workflows, and semantic version constraint operators for managing dependencies.
1 PageBeginnerMar 25, 2026
gem CLI
Managing individual gems directly with RubyGems.
bash
gem install rails # Install a gem globallygem list # List installed gemsgem uninstall rails # Remove a gemgem search rails # Search RubyGems.orggem build mygem.gemspec # Build a gem packagegem push mygem-1.0.0.gem # Publish to RubyGems.org
Gemfile Syntax
Declaring dependencies and environment-specific groups.
ruby
# Gemfilesource "https://rubygems.org"ruby "3.2.2"gem "rails", "~> 7.1.0"gem "pg", ">= 1.4"gem "puma"group :development, :test do gem "rspec-rails" gem "pry"endgroup :production do gem "redis"endgem "rack-cors", git: "https://github.com/cyu/rack-cors.git", branch: "main"
Bundler CLI
Installing and running gems with locked versions.
bash
bundle install # Install gems from Gemfile, write Gemfile.lockbundle update # Update all gems to latest allowed versionsbundle update rails # Update just one gembundle exec rspec # Run a command using bundled gem versionsbundle exec rails serverbundle check # Verify all gems are installedbundle add sidekiq # Add a gem to Gemfile and install it
Version Constraints
How Bundler interprets common version operators.
- ~> 7.1.0- Pessimistic constraint: allows patch updates only, equivalent to >= 7.1.0 and < 7.2.0
- ~> 7.1- Allows minor and patch updates, equivalent to >= 7.1 and < 8.0
- >= 1.4- Any version 1.4 or newer, including major version bumps
- Gemfile.lock- Records the exact resolved versions; commit it to ensure identical installs across environments
- bundle exec- Runs a command in the context of the Gemfile's locked gem versions, avoiding conflicts with system gems
- group blocks- Scope gems to environments (development/test/production) so bundle install --without can skip them
Pro Tip
Commit Gemfile.lock for applications (not for gems you're publishing) so every environment, including CI and production, resolves the exact same dependency versions.
Was this cheat sheet helpful?
Explore Topics
#RubyGemsBundler#RubyGemsBundlerCheatSheet#Programming#Beginner#GemCLI#GemfileSyntax#BundlerCLI#VersionConstraints#CommandLine#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance