1088

I don't use the RI or RDoc output from the gems I install in my machine or in the servers I handle (I use other means of documentation).

Every gem I install installs RI and RDoc documentation by default, because I forget to set --no-ri --no-rdoc.

Is there a way to make those two flags the default?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Ricardo Acras
  • 35,784
  • 16
  • 71
  • 112
  • 8
    It's not a good idea though. I recently needed to write code on the road and when I launched `gem server` I remembered that I had these in my `$HOME/.gemrc` and really killed me... Google isn't always there. – patm Jan 13 '14 at 00:16
  • 7
    Depends on the context. It's a great idea if you can tether or you're doing this on a server that doesn't need gem documentation. – sir-pinecone May 28 '14 at 13:50
  • 5
    with pry one can use `show-source` as an alternative to generated docs. It will show inline comments, which are generally the same content as the ri/rdoc anyway. – max pleaner May 11 '16 at 20:59

13 Answers13

1296

You just add the following line to your local ~/.gemrc file (it is in your home folder):

gem: --no-document

by

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

or you can add this line to the global gemrc config file.

Here is how to find it (in Linux):

strace gem source 2>&1 | grep gemrc

The --no-document option is documented in the RubyGems CLI Reference.

Jirapong
  • 24,074
  • 10
  • 54
  • 72
  • 2
    Anyway to make this a system wide default without editing /etc/skel and every user's home directory? – Hackeron Jan 13 '11 at 03:43
  • 3
    /etc/gemrc didn't work for me, but .gemrc did. I wonder if it's rvm specific that it doesn't read the system gemrc? – wjl Sep 04 '11 at 07:54
  • 1
    Yea I'm using RVM and `/etc/gemrc` doesn't work for me either. – PhilT Sep 21 '11 at 08:27
  • I think opinion was split on the default so it was never changed. – PhilT Sep 21 '11 at 08:28
  • 5
    @gdelfino's answer is the least obtrusive – rxgx May 15 '12 at 00:59
  • 4
    deprecated - please see my answer – James Lim Jun 28 '13 at 14:38
  • 1
    Use `ruby -e "require 'etc';puts Etc.sysconfdir"` to determine the path to your `gemrc` config file. – Michael Mims Nov 15 '13 at 16:26
  • If ruby was compiled with a prefix like `--prefix=/opt/ruby`, then the config file path will be `/opt/ruby/etc/gemrc` (confirmed with ruby 2.3.1) – Hubro Jun 16 '16 at 10:57
  • I didn't have any `gemrc` but my system was quite happy to use a brand new one at `~/.gemrc`. – PJSCopeland Oct 05 '17 at 22:09
  • On FreeBSD, `truss gem source 2>&1 | grep gemrc | awk -F '"' '{print $2}'` is the magic incantation to give you the relevant paths directly. – hd1 Mar 10 '19 at 16:13
  • To find your gemrc file, run `gem env` and find the displayed `SYSTEM CONFIGURATION DIRECTORY` output field. Create or edit the gemrc file in that directory. – oskarpearson Aug 27 '19 at 10:38
507

From RVM’s documentation:

Just add this line to your ~/.gemrc or /etc/gemrc:

gem: --no-document

Note: The original answer was:

install: --no-rdoc --no-ri 
update: --no-rdoc --no-ri 

This is no longer valid; the RVM docs have since been updated, thus the current answer to only include the gem directive is the correct one.

hd1
  • 33,938
  • 5
  • 80
  • 91
gdelfino
  • 11,053
  • 6
  • 44
  • 48
  • 13
    [Since RubyGems version 2.0.0preview2](https://github.com/rubygems/rubygems/blob/master/History.txt), you can instead use `--no-document` or `--document=rdoc` for just rdoc. – iono Apr 09 '13 at 08:06
  • `/etc/gemrc` doesn't seem to work in practice, and [the documentation](http://docs.rubygems.org/read/chapter/11) agrees with it. – MattiSG Jun 17 '13 at 17:40
  • `/etc/gemrc` will work for RVMs binary rubies because they use `--sysconfdir=/etc` you could build your rubies with it too like this: `rvm install 2.0.0 -C --sysconfdir=/etc` to get `/etc/gemrc` working for compiled rubies, otherwise use `$MY_RUBY_HOME/gemrc`. – mpapis Jun 20 '13 at 04:53
  • 3
    I disagree with @mpapis's edit on Jun 20, 2013. He totally changed this answer and there were lots of people that voted for it because they thought it was better than the accepted answer. The person who posted this answer explicitly wrote that they do not want to add those two options to every gem command because it breaks some commands. Before @mpapis totally changed the answer, the code in the answer was: `install: --no-rdoc --no-ri\nupdate: --no-rdoc --no-ri` @mpapis, why did you change the RVM documentation and also change this answer? – David Grayson Jun 27 '13 at 17:12
  • 1
    because it is true, there is no reason to keep two separate lines, keeping track of multi project compatibility is tricky - and the RVM docs get sometimes updated when we find something is off - like in this case, it is not true that rubygems would behave wrong, it's all fine to use `gem:` instead of two separate entries. – mpapis Jun 27 '13 at 19:36
  • RVM docs say to use `rvm_gem_options` in `~/.rvmrc` ie. to disable docs `export rvm_gem_options="--nodocument"` or to enable docs `export rvm_gem_options="--document rdoc,ri"` – bain Jul 27 '13 at 18:48
  • 3
    Use `ruby -e "require 'etc';puts Etc.sysconfdir"` to determine the path to your `gemrc` config file. – Michael Mims Nov 15 '13 at 16:27
  • 2
    This one is deprecated see http://guides.rubygems.org/command-reference/#gem-install – raskhadafi Feb 11 '15 at 09:45
190

Note that --no-ri and --no-rdoc have been deprecated according to the new guides. The recommended way is to use --no-document in ~/.gemrc or /etc/gemrc.

install: --no-document
update: --no-document

or

gem: --no-document
James Lim
  • 12,915
  • 4
  • 40
  • 65
102

On Linux (and probably Mac):

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

This one-liner used to be in comments here, but somehow disappeared.

Slava V
  • 16,686
  • 14
  • 60
  • 63
  • 12
    You should use `>>` in case the user already has a `~/.gemrc`. – nickgrim Feb 24 '13 at 22:56
  • Is there a difference between this `echo 'gem: --no-doc --no-ri' >> ~/.gemrc` and the one you wrote or both have same effect? – ltdev Jan 24 '18 at 17:49
  • 3
    @Lykos `--no-doc --no-ri` is deprecated (see http://guides.rubygems.org/command-reference/#gem_install for options) – Slava V Jan 25 '18 at 18:39
44

/home/{user}/.gemrc

---
:update_sources: true
:sources:
- https://gems.rubyforge.org/
- https://gems.github.com
:benchmark: false
:bulk_threshold: 1000
:backtrace: false
:verbose: true
gem: --no-ri --no-rdoc

http://webonrails.com/2008/12/03/skiping-installation-of-ri-and-rdoc-documentation-while-installing-gems/

David
  • 1,842
  • 2
  • 21
  • 31
  • Thanks for this example, perfect to help me strip out the embedded Ruby that I copied & pasted at some point and then resulted in psych errors while installing RubyGems 1.8.10 under Ruby 1.9.2. – stevenhaddox Sep 03 '11 at 15:02
  • 17
    Please don't post "first result on Google" replies. The first result on Google now shows your reply, self-proving why you shouldn't do this. Thanks, of course, for your answer. – wjl Sep 04 '11 at 07:52
  • 29
    Actually, "first result on Google" shows: ""first result on Google" shows: ""first result on Google" shows: ""... ERROR: Stack Overflow. – Félix Saparelli Sep 22 '11 at 06:53
  • I have to add my thanks for steve's comment (above). I was pulling my hair out as to why I could not install the latest RubyGems. Turns out I had a malformed .gemrc file as well. I kept getting this error: ../.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/psych.rb:148:in `parse': couldn't parse YAML at line 2 column 10 (Psych::SyntaxError) – wchrisjohnson Nov 04 '11 at 01:35
  • and if you type "google" into google you'll break the internet – ecoologic Jun 14 '21 at 01:33
  • 1
    `---` ` :update_sources: true ` ` :sources: ` - https://rubygems.org/ #- https://gems.rubyforge.org/ #- https://gems.github.com :benchmark: false` :bulk_threshold: 1000 ` :backtrace: false ` :verbose: true` ` gem: --no-document` ` With https :) – avisri Apr 08 '23 at 14:16
33

On Windows XP the path to the .gemrc file is

c:\Documents and Settings\All Users\Application Data\gemrc 

and this file is not created by default, you should create it yourself.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Viachaslau Tysianchuk
  • 1,680
  • 19
  • 22
16

A oneliner for the windows 7 users:

(echo install: --no-document && echo update: --no-document) >> c:\ProgramData\gemrc

skywinder
  • 21,291
  • 15
  • 93
  • 123
Gabe
  • 495
  • 4
  • 7
10

You can specify default options using the .gemrc configuration file.

Documentation about gem configuration file

Vincent Robert
  • 35,564
  • 14
  • 82
  • 119
7

As mentioned above, put gem: --no-document in your gem file. However, the system-wide gemrc will not always necessarily go into /etc/gemrc. If you are using RVM, or you have Ruby installed under /usr/local/bin, it needs to go in a different location. You can find this location by running irb and typing...

require 'rubygems'
Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE

See the original post on this over here.

Community
  • 1
  • 1
Adam
  • 1,755
  • 20
  • 31
5

On Windows7 the .gemrc file is not present, you can let Ruby create one like this (it's not easy to do this in explorer).

gem sources --add http://rubygems.org

You will have to confirm (it's unsafe). Now the file is created in your userprofile folder (c:\users\)

You can edit the textfile to remove the source you added or you can remove it with

gem sources --remove http://rubygems.org
peter
  • 41,770
  • 5
  • 64
  • 108
5

Step by steps:

To create/edit the .gemrc file from the terminal:

vi  ~/.gemrc

You will open a editor called vi. paste in:

gem: --no-ri --no-rdoc

click 'esc'-button.

type in:

:exit

You can check if everything is correct with this command:

sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit ~/.gemrc
Andreas
  • 2,287
  • 2
  • 23
  • 26
  • 2
    To clarify, that last command is OS X specific. It opens the `~/.gemrc` file in a texteditor. – Martijn Heemels Jan 16 '12 at 18:18
  • 1
    ~ is representation for home directory. (the following stuff in caps are environment variables) Order of checking directories for .gemrc: 1. Use HOME if it is defined. 2. Use USERPROFILE if it is defined. 3. Use HOMEDRIVE and HOMEPATH together if they are defined. 4. Use the path you get by having Ruby expand “~”. 5. Use “C:/” if you are on a Windows machine. That is per: http://docs.rubygems.org/read/chapter/12 – Gary S. Weaver Jan 30 '12 at 20:55
  • You shouldn't need `sudo` to edit your own user's `~/.gemrc`. – jbbuckley Feb 05 '17 at 14:26
3

For Windows users, Ruby doesn't set up .gemrc file. So you have to create .gemrc file in your home directory (echo %USERPROFILE%) and put following line in it:

gem: --no-document

As already mentioned in previous answers, don't use --no-ri and --no-rdoc cause its deprecated. See it yourself:

gem help install
Rajkaran Mishra
  • 4,532
  • 2
  • 36
  • 61
0

~/.gemrc file

---
gem: --no-document
:update_sources: true
:sources:
- https://rubygems.org/
:benchmark: false
:bulk_threshold: 1000
:backtrace: false
:verbose: true

Use HTTPS and a known source. An improvement over the above answer.

PS: I tried to post the comment and could not get it to format nicely. Finally resorted to posting a new answer.

avisri
  • 131
  • 4