Mastodon

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.

Rubygems: Installing downloaded gems

I set aside some time this evening to move one of my projects forward. Just as I was getting into it I realised I needed to install some gems. The normally quick “sudo gem install blah” took forever.  After several frustrating minutes, rubygems coughed up the following error:

WARNING:  RubyGems 1.2+ index not found for:
http://gemcutter.org
http://gems.rubyforge.org/

RubyGems will revert to legacy indexes degrading performance.

Degrading performance it certainly was. Both aggravated and curious, I embarked on a flurry of pings, nslookups and GET requests which seem to indicate that Rubygems.org is, in fact, down. Interestingly, Heroku, which hosts rubygems.org was up, reachable and blazing fast. Not wanting to totally waste an evening I figured now was a pretty good time to look into installing gems manually. Luckily it was really easy, but rubygems generally makes it so you don’t need to consider any other options.

The gem I was after offered two options: download as a tar file or a gem file.

Installing from the tar file seems to be a matter of extracting it into /usr/lib/ruby/gems/1.8/gems/ and a quick look at the README file indicated I needed to run setup.rb. That might not hold for all gems but it worked for that one.

Just out of interest I also tried installing from the downloaded gem file. It turns out that its even easier. After downloading the gem file all it took was:

mike@sleepycat:~$ cd Downloads/
mike@sleepycat:~/Downloads$ sudo gem install ruby-openid-2.1.8.gem
Successfully installed ruby-openid-2.1.8
1 gem installed
Installing ri documentation for ruby-openid-2.1.8…
Installing RDoc documentation for ruby-openid-2.1.8…

Not difficult, but not something I had had to do before. Hopefully Rubygems.org will be back up shortly and I won’t have to do again any time soon.I can understand the urge to centralise like Rubygems.org has done with the gem hosting community. The problem is that while you might save some bucks and/or some hassle by centralising, you are multiplying the impact of the inevitable. At least tonight, it doesn’t feel worth it.