gem & Bundler Commands

gem & bundler commands cheatsheet.

Install and update Ruby gems, manage a Gemfile with Bundler, and run tasks with bundle exec — the commands you use every day. Tap to copy.

Installing gems
gem install <gem>Install the latest version of a gem
gem install <gem> -v 1.2.3Install a specific version of a gem
gem update <gem>Update a gem to the latest version
gem update --systemUpdate RubyGems itself to the latest version
gem uninstall <gem>Remove an installed gem
Info
gem listList all installed gems
gem list <pattern>List installed gems matching a pattern
gem which <gem>Show the path a gem is loaded from
gem info <gem>Show details about an installed gem
gem environmentShow RubyGems configuration and paths
gem --versionPrint the installed RubyGems version
Bundler basics
bundle initCreate a new Gemfile in the current folder
bundle installInstall the gems listed in the Gemfile
bundle add <gem>Add a gem to the Gemfile and install it
bundle updateUpdate all gems to the latest allowed versions
bundle update <gem>Update a single gem within its constraints
bundle remove <gem>Remove a gem from the Gemfile
Bundler running
bundle exec <cmd>Run a command with the bundled gem versions
bundle exec rake <task>Run a Rake task with bundled gems
bundle showList the gems in the current bundle
bundle outdatedShow bundled gems with newer versions available
Building & maintenance
gem build <name>.gemspecBuild a gem from a gemspec
gem push <name>.gemPublish a built gem to RubyGems.org
gem cleanupRemove old versions of installed gems
bundle lockUpdate Gemfile.lock without installing gems

gem vs Bundler

Ruby has two layers of tooling that work together. gem is the RubyGems command that installs, updates and removes individual gems on your system — gem install <gem> pulls a library from RubyGems.org and makes it available. Bundler (the bundle command) sits on top and manages a whole project's dependencies through a Gemfile, resolving a compatible set of versions and pinning them in Gemfile.lock so every machine installs exactly the same thing.

Installing gems

For a single tool you want everywhere, gem install <gem> is all you need, and gem install <gem> -v 1.2.3 pins an exact version when a project needs one. Multiple versions of a gem can live side by side. gem update <gem> moves a gem forward, while gem update --system upgrades RubyGems itself. When you no longer need something, gem uninstall <gem> cleans it out.

Working with a Gemfile

Inside a project you'll mostly use Bundler. bundle init creates a starter Gemfile, bundle add <gem> adds a dependency and installs it, and bundle install installs everything the Gemfile lists — the first command you'll run after cloning a Ruby project. bundle update refreshes versions within your constraints, and the crucial bundle exec <cmd> runs a command using exactly the locked versions so you never accidentally pick up a mismatched global gem.

Building and publishing

If you maintain a gem, gem build <name>.gemspec packages it into a .gem file and gem push <name>.gem publishes it to RubyGems.org. Housekeeping like gem cleanup removes old versions, and bundle lock refreshes Gemfile.lock without installing. These pair naturally with the Git commands for version control and the Docker commands when you containerise your app.

FAQ

What's the difference between gem install and bundle install?
gem install adds a single gem to your system (or Ruby version) so it's available everywhere. bundle install reads your project's Gemfile, resolves compatible versions of every gem your project declares, and locks them in Gemfile.lock so the whole team gets the same versions.
What does bundle exec do?
bundle exec runs a command using exactly the gem versions pinned in your Gemfile.lock, instead of whatever version happens to be installed globally. It prevents version conflicts — for example bundle exec rake runs the rake and dependencies your project locked.
How do I install a specific version of a gem?
Use gem install <gem> -v 1.2.3 to install an exact version. Multiple versions can coexist, and Bundler or the -v flag decides which one a command uses.

More cheatsheets