Reason #70 • March 11th, 2026

Viewing and editing gems with bundle open

One of the most useful Bundler commands is bundle open <gem-name>, which opens the source code of an installed gem in your favourite editor (as defined by the $EDITOR environment variable). This is a fantastic way to quickly understand how a gem works.

As discussed yesterday, since only a single version of a gem can be active at a time, you don't need to worry about which version of the gem to open, but can remain confident that you're looking at the source code of the version that's actually being used in your project.

A less obvious use case is to use it to literally edit the source code of a gem to, e.g. trigger a debugger or test out a patch before moving towards a full pull request.

I've used this approach countless times over the years and recommend making a habit out of it. Just be aware that when you're running bundle open, you're editing the source code of the gem as it is installed on your machine, so any changes you make will affect all projects using that gem until you either revert the changes or reinstall the gem. Keep files open while editing to ensure you can undo all edits before finally closing!

Also keep in mind that your application must be restarted each time you want to try out your changes, since a gem's code is only loaded once per process.

History

The first solution I remember using to open installed gems in an editor was the gem edit command courtesy of the gemedit gem, released in 2008.

Bundler added the bundle open command in its first patch release, 1.0.1, released in 2010.

It wasn't until RubyGems 2.3, released in 2014, that gem open was introduced as a built-in command to RubyGems itself, but it was mostly redundant by then since usage of Bundler was already ubiquitous.