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.
gem install <gem>Install the latest version of a gemgem install <gem> -v 1.2.3Install a specific version of a gemgem update <gem>Update a gem to the latest versiongem update --systemUpdate RubyGems itself to the latest versiongem uninstall <gem>Remove an installed gemgem listList all installed gemsgem list <pattern>List installed gems matching a patterngem which <gem>Show the path a gem is loaded fromgem info <gem>Show details about an installed gemgem environmentShow RubyGems configuration and pathsgem --versionPrint the installed RubyGems versionbundle initCreate a new Gemfile in the current folderbundle installInstall the gems listed in the Gemfilebundle add <gem>Add a gem to the Gemfile and install itbundle updateUpdate all gems to the latest allowed versionsbundle update <gem>Update a single gem within its constraintsbundle remove <gem>Remove a gem from the Gemfilebundle exec <cmd>Run a command with the bundled gem versionsbundle exec rake <task>Run a Rake task with bundled gemsbundle showList the gems in the current bundlebundle outdatedShow bundled gems with newer versions availablegem build <name>.gemspecBuild a gem from a gemspecgem push <name>.gemPublish a built gem to RubyGems.orggem cleanupRemove old versions of installed gemsbundle lockUpdate Gemfile.lock without installing gemsgem 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.