Ruby gem installations sometimes can be very slow because of the on-the-fly document generation post-process.
You can disable this behaviour by providing following options to gem command:
For older versions:
$ gem install rails --no-ri --no-rdoc
For newer versions:
$ gem install rails --no-document
If you want to make this behaviour as default, you just need to enter following line into ~/.gemrc file:
gem: --no-document
Please note that,
bundlealready skips document generation process by default, above configuration only needed for the installation bygemcommand.