Installing RubyGems faster

One of the things I learned about over summer while using Rails quite a bit was that the gem installation process can be a slower one, especially when you are installing lots of gems. In many cases it is not even installing the actual gem that takes all the time, its generating the rdoc and ri information. In my experience very few developers actually use the rdoc information on their local boxes, and no one should be looking at rdocs on your production environment, so why bother installing them?
You can prevent those from being created by adding special flags to the end of the install command (e.g. "gem install rspec --no-ri --no-rdoc"). This is nice but I seem to always forget to add the flags until its too late and the gems are already installing. This can be fixed by adding the flags to your gemrc so it will happen automatically. Simply open your ~/.gemrc file and add the following line to the end "gem: --no-ri --no-rdoc". My .gemrc was created by root so I needed sudo to edit the file, but this may not be the case for you. Just for reference my .gemrc now looks like this:

:benchmark: false
:backtrace: false
:update_sources: true
:bulk_threshold: 1000
:verbose: true
gem: --no-ri --no-rdoc

As a quick test I installed the cucumber gem on my local box without the flags and it took 31 seconds. After changing my gemrc to include the flags the same installation time took 13 seconds, a pretty nice improvement. If you are deploying your app in an environment like RightScale where your machines are configured at boot-time I would certainly include that line in your gemrc, it should speed up the gem installation process a good deal.


Post a Comment