Ruby on Rails

Get rid of the gem documentation once & for all by specifying it on .gemrc

When installing a new gem using the gem install command, the documentation generation takes time and space on your development machine. This minipost, will demonstrate the common ways to avoid documentation installation when using gem install command. You could eliminate gem documentation, when you install new gems by adding flags to gem install command or add couple of settings to .gemrc file.

To demonstrate the cases, we will use the bundler gem. Therefore, let’s say we need to install a new bundler version to our development machine. Check what versions have been already installed by:

$ gem list bundler

A typical output, depending on the bundler versions you have already installed, could be the following:

*** LOCAL GEMS ***

bundler (1.17.1, 1.16.6, 1.16.5)

The latest bundler in this test machine is 1.17.1. To get informed about the latest version visit ruby gems and at this point in time the latest bundler version is 2.0.1. For the sake of this example, let’s try and install this specific version of bundler to our development machine without the use of any flags to skip documentation:

$ gem install bundler -v 2.0.1
Fetching: bundler-2.0.1.gem (100%)
Successfully installed bundler-2.0.1
Parsing documentation for bundler-2.0.1
Installing ri documentation for bundler-2.0.1
Done installing documentation for bundler after 2 seconds
1 gem installed

We have successfully installed the new bundler version and from the above output is clear that we have also installed the relevant gem documentation. Now, let's uninstall this specific gem version and try again to see if we can avoid the documentation installation.

$ gem uninstall bundler -v 2.0.1
Successfully uninstalled bundler-2.0.1

According to the latest ruby gems command reference you can use the flag -N or the flag -​-no-document whilst installing a new gem to avoid documentation generation. Try a new installation of bundler with the new flag:

$ gem install bundler -v 2.0.1 -​-no-document
$ gem install bundler -v 2.0.1 -​N
Fetching: bundler-2.0.1.gem (100%)
Successfully installed bundler-2.0.1
1 gem installed

As you can see, if you try either of the above flags during new gem installation, you will manage to install the new gem without its documentation. In order to avoid specifying everytime the --no-document or -N flags, you can create a global setting on your .gemrc file and you will never install again any of the documentation.

echo the following to your .gemrc file:

echo "gem: --no-document" > ~/.gemrc

View your .gemrc file:

$ cat ~/.gemrc
gem: --no-document

Uninstall again the previously installed bundler gem with:

$ gem uninstall bundler -v 2.0.1

Install it again with:

$ gem install bundler -v 2.0.1

Finally, inspect the command output:

Fetching: bundler-2.0.1.gem (100%)
Successfully installed bundler-2.0.1
1 gem installed

There you go, no gem documentation was installed, without using the --no-document flag during installation. From now on, you will install your gems without any documentation generation. By getting rid of the documentation installation, you can significantly improve the speed of every gem installation, during development. If for some reason, you need the documentation or you need to avoid the usage of your .gemrc file, you can do such using the --norc flag, like the following:

$ gem install bundler -v 2.0.1 --norc

The above will install the gem with its documentation, ignoring all the settings and flags that appear on your .gemrc file.

Additional information: