Question
When installing Ruby gems, RI and RDoc documentation are generated by default. I do not use this documentation on my local machine or on servers, and I often forget to pass the --no-ri --no-rdoc flags.
Is there a way to configure RubyGems so these options are used by default for every gem install command?
Short Answer
By the end of this page, you will understand how RubyGems command defaults work, how to configure gem install to skip documentation automatically, and where to place that configuration so it applies consistently on your machine or server.
Concept
RubyGems allows you to define default command-line options in a configuration file. This is useful when you repeatedly use the same flags with gem install.
In this case, the underlying concept is tool configuration through a user or system config file. Instead of remembering to type the same command options every time, you store them once in RubyGems configuration.
Historically, RubyGems generated RI and RDoc documentation for installed gems. If you do not use those local docs, disabling them can:
- save installation time
- reduce disk usage
- keep commands shorter
- make server setup scripts more predictable
The main idea is that gem install behavior can be customized globally by editing the .gemrc file.
A common configuration looks like this:
gem: --no-ri --no-rdoc
On newer RubyGems versions, documentation handling changed, and a more modern option is often:
gem: --no-document
So the broader lesson is not only about RI and RDoc. It is about understanding that many developer tools support persistent defaults through configuration files.
Mental Model
Think of gem install like a machine with buttons.
Normally, every time you use it, you press extra buttons such as "skip docs". That works, but it is repetitive.
A config file is like changing the machine's default settings once, so every future use starts the way you prefer.
Instead of saying:
- "Install this gem"
- "Also skip RI"
- "Also skip RDoc"
...every single time, you tell RubyGems:
- "Whenever I install gems, assume I want docs skipped unless I say otherwise."
That is the purpose of .gemrc: storing your preferred defaults.
Syntax and Examples
RubyGems reads settings from a YAML configuration file named .gemrc.
Basic configuration
For older RubyGems versions:
gem: --no-ri --no-rdoc
For newer RubyGems versions:
gem: --no-document
Where to put it
A common user-level location is:
~/.gemrc
Example:
echo 'gem: --no-document' >> ~/.gemrc
Or manually create/edit the file:
gem: --no-document
What this does
After saving the config, this command:
gem install rails
behaves more like:
gem install rails --no-document
without you having to type the flag every time.
Step by Step Execution
Consider this setup:
gem: --no-document
stored in:
~/.gemrc
Now run:
gem install rake
Step-by-step
-
RubyGems starts the
installcommand. -
It checks its configuration sources, including your
.gemrcfile. -
It finds the line:
gem: --no-document -
RubyGems applies that option as a default for gem commands.
-
The
rakegem is downloaded and installed. -
Documentation generation is skipped.
-
The install finishes faster and uses less space.
Older version trace
If your RubyGems version expects older flags, this config may be used:
gem:
Real World Use Cases
Local development machines
Developers often install many gems while switching projects. Skipping RI and RDoc avoids repeated wasted time if local docs are never used.
CI and build servers
Continuous integration environments should be fast and minimal. Disabling documentation reduces setup time during dependency installation.
Production servers
Servers usually do not need local gem documentation. Keeping installs lean helps reduce disk usage and deployment noise.
Container images
When building Docker images for Ruby apps, every unnecessary file increases image size. Skipping docs helps keep images smaller.
Provisioning scripts
Automation tools such as shell scripts, Ansible, or Chef benefit from predictable defaults. A .gemrc file avoids repeating flags in every script.
Real Codebase Usage
In real projects, developers usually combine this idea with broader environment setup practices.
Common patterns
Developer machine bootstrap
A setup script may create ~/.gemrc during onboarding:
echo 'gem: --no-document' > ~/.gemrc
This ensures every developer gets the same default behavior.
Server provisioning
Infrastructure scripts often add RubyGems config as part of machine preparation so deploys and maintenance tasks are faster.
Minimal Docker environments
A Dockerfile may include a RubyGems configuration step before installing dependencies.
Configuration over repetition
Instead of writing:
gem install bundler --no-document
gem install rake --no-document
gem install rspec --no-document
teams prefer one config file and shorter commands:
gem install bundler
gem install rake
gem install rspec
Related coding habit
This reflects a broader programming practice: move repeated options into configuration when they represent a stable default.
Common Mistakes
1. Using old flags on a newer RubyGems version
Older examples often show:
gem: --no-ri --no-rdoc
On newer RubyGems versions, the preferred option is usually:
gem: --no-document
If the old flags do not work, check your RubyGems version and use the newer option.
2. Writing invalid YAML
Broken example:
gem --no-document
This is invalid because YAML needs a key-value structure.
Correct:
gem: --no-document
3. Editing the wrong file
Some users change shell config files like .bashrc or .zshrc expecting RubyGems to read them automatically.
RubyGems uses .gemrc, not your shell profile, for this setting.
4. Expecting system-wide behavior from a user config
~/.gemrc usually affects only the current user. If you manage multiple users or automated system accounts, each context may need its own configuration.
Comparisons
| Approach | Example | Best for | Notes |
|---|---|---|---|
| Per-command flags | gem install rails --no-document | One-off installs | Repetitive if used often |
| User config file | ~/.gemrc with gem: --no-document | Personal default setup | Most convenient for daily use |
| System or automated setup | Provisioning scripts create .gemrc | Teams, servers, containers | Good for consistency |
Old flags vs new flag
| Option | RubyGems era | Meaning |
|---|
Cheat Sheet
# Older RubyGems
gem: --no-ri --no-rdoc
# Newer RubyGems
gem: --no-document
# Typical config file location
~/.gemrc
# Example: create/update config
printf 'gem: --no-document\n' > ~/.gemrc
Rules to remember
- Use
.gemrcto store default RubyGems options. - Use
--no-documenton newer RubyGems versions. - Use
--no-ri --no-rdoconly if your RubyGems version still expects them. .gemrcis usually per-user, not automatically global.- The config file uses YAML syntax.
Quick check
cat ~/.gemrc
Expected content:
gem: --no-document
FAQ
How do I stop gem install from generating documentation by default?
Create or edit ~/.gemrc and add:
gem: --no-document
Should I use --no-ri --no-rdoc or --no-document?
Use --no-document on newer RubyGems versions. Use --no-ri --no-rdoc only if you are working with an older setup.
Where is the RubyGems config file located?
For a user-specific setup, it is commonly located at ~/.gemrc.
Does this affect all users on a server?
No, not usually. A file in ~/.gemrc applies to the current user account.
Can I still install documentation for one gem later?
Yes. Defaults are just defaults. You can override behavior with command-line options when needed.
Why would developers disable gem documentation?
Usually to save installation time, reduce disk usage, and simplify automated environments.
Is this safe for production servers?
Yes, if you do not rely on locally generated gem docs on that server.
Mini Project
Description
Create a small Ruby environment setup task that configures RubyGems to skip documentation by default. This mirrors a real developer onboarding or server provisioning step and helps you practice using config files instead of repeating command flags.
Goal
Set up a .gemrc file that makes future gem install commands skip documentation automatically.
Requirements
- Check whether a
~/.gemrcfile already exists. - If it does not exist, create it.
- Add a RubyGems default option that disables documentation generation.
- Verify the file contents after saving.
- Test the configuration by installing a gem.
Keep learning
Related questions
How to Call Shell Commands from Ruby and Capture Output
Learn how to run shell commands in Ruby, capture output, check exit status, and choose the right method for scripts and apps.
How to Check Whether a String Contains a Substring in Ruby
Learn how to check if a string contains a substring in Ruby using include?, match, and multiline string examples.
How to Check if a Hash Key Exists in Ruby
Learn how to check whether a specific key exists in a Ruby hash using key?, has_key?, and include? with clear examples.