Ruby
Gems
Coding Tutorial
Software Development
Command Line Options

How to make --no-ri --no-rdoc the default for gem install?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

When working with Ruby, managing documentation files when installing gems can be cumbersome, particularly if you are deploying to production environments where these documents are irrelevant, but consume disk space. By default, the RubyGems package manager installs documentation for each gem, which includes RI (Ruby Index) and RDoc (Ruby Documentation) files. For most developers, especially those in production environments, these files are unnecessary, and skipping their installation can save time and resources.

Understanding the --no-ri and --no-rdoc Options

When you install a gem using RubyGems, you can skip the creation of document files by using the --no-ri and --no-rdoc options. Here’s what these options do:

  • --no-ri: This option prevents the creation of Ruby Index (RI) files, which are used for offline documentation.
  • --no-rdoc: This option skips the generation of RDoc files, Ruby's default format for inline documentation.

Making --no-ri --no-rdoc The Default

To avoid manually typing --no-ri --no-rdoc every time you install a gem, you can configure RubyGems to set these options as default. This configuration can be done globally or on a per-user basis.

Global Configuration

To set these options globally, you need to modify the .gemrc file which RubyGems reads every time it runs. This file can be found typically in the root directory of the system (for all users) or inside the user's home directory for a specific user.

  1. Open or create a .gemrc file in the desired location:
    • Global setting: /etc/gemrc
    • User-specific setting: ~/.gemrc
  2. Add the following lines to the .gemrc file:
yaml
install: --no-document
update: --no-document

The --no-document option is a shorthand for both --no-ri and --no-rdoc. This ensures that none of the documentation files are created when any gem is installed or updated.

Per-Project Configuration

In some cases, you might want to disable documentation only for specific projects. This can be achieved through the Bundler tool:

  1. Navigate to your project directory.
  2. Create or edit a Gemfile in your project root if not already present.
  3. At the top of the Gemfile, add the following:
ruby
# Skip documentation for all gems
bundle config set --local no-document true

This sets the no-document configuration only for the specific project.

Verifying the Configuration

You can check whether the no-document configuration is set by running the following command:

bash
gem install GEMNAME --explain

This command will show what actions RubyGems will take when installing the gem, including whether documentation files are going to be installed.

Summary Table

Configuration LevelFile LocationCommand ExampleDocumentation Skipped
Global/etc/gemrcecho "install: --no-document" >> /etc/gemrcYes
User~/.gemrcecho "install: --no-document" >> ~/.gemrcYes
Project-specificProject's Gemfileecho "bundle config set --local no-document true" >> GemfileYes

Conclusion

Setting --no-ri --no-rdoc as the default for gem installations can speed up the gem installation process, save disk space, and streamline deployment operations. By configuring RubyGems or Bundler as described above, you can ensure a more efficient environment for your Ruby development and deployment workflows.


Course illustration
Course illustration

All Rights Reserved.