Rubygems: Finding all available versions of a gem

Yesterday I was asked if I knew what the highest available version in the Rails 1.x line was. I knew it was going to be a variation of “gem list” but it took a little fiddling to get it right. This is just a little thing but its not something you end up doing often and it was useful so I thought I would write it down here.

Strangely “gem list” accepts a string argument (in this case “rails”) that it uses to search for any gem starting with that string. It would be nice to be able to be more specific than “rails*” but it does the job. So here we go.

Gem list –remote seems to return the curent version only:

mike@sleepycat:~$ gem list –remote rails
rails (2.3.8 ruby)
rails-action-args (0.1.1 ruby)

Including –all gets all the released versions:

mike@sleepycat:~$ gem list –remote rails –all

*** REMOTE GEMS ***

rails (2.3.8 ruby, 2.3.7 ruby, 2.3.6 ruby, 2.3.5 ruby, 2.3.4 ruby, 2.3.3 ruby, 2.3.2 ruby, 2.2.3 ruby, 2.2.2 ruby, 2.1.2 ruby, 2.1.1 ruby, 2.1.0 ruby, 2.0.5 ruby, 2.0.4 ruby, 2.0.2 ruby, 2.0.1 ruby, 2.0.0 ruby, 1.2.6 ruby, 1.2.5 ruby, 1.2.4 ruby, 1.2.3 ruby, 1.2.2 ruby, 1.2.1 ruby, 1.2.0 ruby, 1.1.6 ruby, 1.1.5 ruby, 1.1.4 ruby, 1.1.3 ruby, 1.1.2 ruby, 1.1.1 ruby, 1.1.0 ruby, 1.0.0 ruby, 0.14.4 ruby, 0.14.3 ruby, 0.14.2 ruby, 0.14.1 ruby, 0.13.1 ruby, 0.13.0 ruby, 0.12.1 ruby, 0.12.0 ruby, 0.11.1 ruby, 0.11.0 ruby, 0.10.1 ruby, 0.10.0 ruby, 0.9.5 ruby, 0.9.4.1 ruby, 0.9.4 ruby, 0.9.3 ruby, 0.9.2 ruby, 0.9.1 ruby, 0.9.0 ruby, 0.8.5 ruby, 0.8.0 ruby)

And if you wondered, as I did, “Where is Rails 3 in that list?”. You need to include a flag for prereleases:

mike@sleepycat:~$ gem list –remote –prerelease rails –all

rails (3.0.0.beta4 ruby, 3.0.0.beta3 ruby, 3.0.0.beta2 ruby, 3.0.0.beta ruby, 2.3.8 ruby, 2.3.8.pre1 ruby, 2.3.7 ruby, 2.3.6 ruby, 2.3.5 ruby, 2.3.4 ruby, 2.3.3 ruby, 2.3.2 ruby, 2.2.3 ruby, 2.2.2 ruby, 2.1.2 ruby, 2.1.1 ruby, 2.1.0 ruby, 2.0.5 ruby, 2.0.4 ruby, 2.0.2 ruby, 2.0.1 ruby, 2.0.0 ruby, 1.2.6 ruby, 1.2.5 ruby, 1.2.4 ruby, 1.2.3 ruby, 1.2.2 ruby, 1.2.1 ruby, 1.2.0 ruby, 1.1.6 ruby, 1.1.5 ruby, 1.1.4 ruby, 1.1.3 ruby, 1.1.2 ruby, 1.1.1 ruby, 1.1.0 ruby, 1.0.0 ruby, 0.14.4 ruby, 0.14.3 ruby, 0.14.2 ruby, 0.14.1 ruby, 0.13.1 ruby, 0.13.0 ruby, 0.12.1 ruby, 0.12.0 ruby, 0.11.1 ruby, 0.11.0 ruby, 0.10.1 ruby, 0.10.0 ruby, 0.9.5 ruby, 0.9.4.1 ruby, 0.9.4 ruby, 0.9.3 ruby, 0.9.2 ruby, 0.9.1 ruby, 0.9.0 ruby, 0.8.5 ruby, 0.8.0 ruby)

Don’t forget that when the output gets to long (like when you ask for details) you can always redirect it into a file:

mike@sleepycat:~$ gem list –remote –details –prerelease rails –all > gemlist.txt

Like I said… a little thing, but useful to know about.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s