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.
- Open or create a
.gemrcfile in the desired location:- Global setting:
/etc/gemrc - User-specific setting:
~/.gemrc
- Add the following lines to the
.gemrcfile:
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:
- Navigate to your project directory.
- Create or edit a
Gemfilein your project root if not already present. - At the top of the
Gemfile, add the following:
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:
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 Level | File Location | Command Example | Documentation Skipped |
| Global | /etc/gemrc | echo "install: --no-document" >> /etc/gemrc | Yes |
| User | ~/.gemrc | echo "install: --no-document" >> ~/.gemrc | Yes |
| Project-specific | Project's Gemfile | echo "bundle config set --local no-document true" >> Gemfile | Yes |
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.

