How To Specify The Version Of A Gem To Use From The Command-Line

Sometimes you have multiple versions of a gem installed.

$ gem list | ag "^rails "
rails (5.2.0, 5.0.7, 5.0.6)

But when I invoke the gem executable the latest version is always used.

$ rails -v
Rails 5.2.0

So how do you specify the version of the gem to use? You use _underscores_.

$ rails _5.0.7_ -v
Rails 5.0.7

This doesn’t seem to be documented anywhere, but luckily we have StackOverflow.