# Configure IRB
## Configuration Sources
IRB configurations can be set through multiple sources, each with its own precedence:
1. **Command-Line Options**: When some options are specified when starting IRB, they can override default settings.
2. **Configuration File**: If present, IRB reads a configuration file containing Ruby code to set configurations.
3. **Environment Variables**: Certain environment variables influence IRB's behavior.
4. **Hash `IRB.conf`**: This hash holds the current configuration settings, which can be modified during a session.
### Configuration File Path Resolution
IRB searches for a configuration file in the following order:
1. `$IRBRC`
2. `$XDG_CONFIG_HOME/irb/irbrc`
3. `$HOME/.irbrc`
4. `$HOME/.config/irb/irbrc` (only if `XDG_CONFIG_HOME` is _not_ set)
5. `.irbrc` in the current directory
6. `_irbrc` in the current directory
7. `$irbrc` in the current directory
If the `-f` command-line option is used, no configuration file is loaded.
Method `conf.rc?` returns `true` if a configuration file was read, `false` otherwise. Hash entry `IRB.conf[:RC]` also contains that value.
## Environment Variables
- `NO_COLOR`: Disables IRB's colorization.
- `IRB_USE_AUTOCOMPLETE`: Setting to `false` disables autocompletion.
- `IRB_COMPLETOR`: Configures auto-completion behavior (`regexp` or `type`).
- `IRB_COPY_COMMAND`: Overrides the default program used to interface with the system clipboard.
- `VISUAL` / `EDITOR`: Specifies the editor for the `edit` command.
- `IRBRC`: Specifies the rc-file for configuration.
- `XDG_CONFIG_HOME`: Used to locate the user-specific rc-file (i.e. `$XDG_CONFIG_HOME/irb/irbrc` instead of `$HOME/.config/irb/irbrc`).
- `RI_PAGER` / `PAGER`: Specifies the pager for documentation.
- `IRB_LANG`, `LC_MESSAGES`, `LC_ALL`, `LANG`: Determines the locale.
## Hash `IRB.conf`
The initial entries in hash `IRB.conf` are determined by:
- Default values.
- Command-line options, which may override defaults.
- Direct assignments in the configuration file.
You can see the hash by typing `IRB.conf`. Below are the primary entries:
- `:AP_NAME`: IRB {application name}[rdoc-ref:IRB@Application+Name];
initial value: `'irb'`.
- `:AT_EXIT`: Array of hooks to call
{at exit}[rdoc-ref:IRB@IRB];
initial value: `[]`.
- `:AUTO_INDENT`: Whether {automatic indentation}[rdoc-ref:IRB@Automatic+Indentation]
is enabled; initial value: `true`.
- `:BACK_TRACE_LIMIT`: Sets the {back trace limit}[rdoc-ref:IRB@Tracer];
initial value: `16`.
- `:COMMAND_ALIASES`: Defines input {command aliases}[rdoc-ref:IRB@Command+Aliases];
initial value:
{
"$": :show_source,
"@": :whereami,
}
- `:CONTEXT_MODE`: Sets the {context mode}[rdoc-ref:IRB@Context+Mode],
the type of binding to be used when evaluating statements;
initial value: `4`.
- `:ECHO`: Whether to print ({echo}[rdoc-ref:IRB@Return-Value+Printing+-28Echoing-29])
return values;
initial value: `nil`, which would set `conf.echo` to `true`.
- `:ECHO_ON_ASSIGNMENT`: Whether to print ({echo}[rdoc-ref:IRB@Return-Value+Printing+-28Echoing-29])
return values on assignment;
initial value: `nil`, which would set `conf.echo_on_assignment` to `:truncate`.
- `:EVAL_HISTORY`: How much {evaluation history}[rdoc-ref:IRB@Evaluation+History]
is to be stored; initial value: `nil`.
- `:EXTRA_DOC_DIRS`: Array of
{RI documentation directories}[rdoc-ref:IRB@RI+Documentation+Directories]
to be parsed for the documentation dialog;
initial value: `[]`.
- `:IGNORE_EOF`: Whether to ignore {end-of-file}[rdoc-ref:IRB@End-of-File];
initial value: `false`.
- `:IGNORE_SIGINT`: Whether to ignore {SIGINT}[rdoc-ref:IRB@SIGINT];
initial value: `true`.
- `:INSPECT_MODE`: Whether to use method `inspect` for printing
({echoing}[rdoc-ref:IRB@Return-Value+Printing+-28Echoing-29]) return values;
initial value: `true`.
- `:IRB_LIB_PATH`: The path to the {IRB library directory}[rdoc-ref:IRB@IRB+Library+Directory]; initial value:
- `"RUBY_DIR/lib/ruby/gems/RUBY_VER_NUM/gems/irb-IRB_VER_NUM/lib/irb"`,
where:
- RUBY_DIR is the Ruby installation dirpath.
- RUBY_VER_NUM is the Ruby version number.
- IRB_VER_NUM is the IRB version number.
- `:IRB_NAME`: {IRB name}[rdoc-ref:IRB@IRB+Name];
initial value: `'irb'`.
- `:IRB_RC`: {Configuration monitor}[rdoc-ref:IRB@Configuration+Monitor];
initial value: `nil`.
- `:LC_MESSAGES`: {Locale}[rdoc-ref:IRB@Locale];
initial value: IRB::Locale object.
- `:LOAD_MODULES`: deprecated.
- `:MAIN_CONTEXT`: The {context}[rdoc-ref:IRB@Session+Context] for the main IRB session;
initial value: IRB::Context object.
- `:MEASURE`: Whether to
{measure performance}[rdoc-ref:IRB@Performance+Measurement];
initial value: `false`.
- `:MEASURE_CALLBACKS`: Callback methods for
{performance measurement}[rdoc-ref:IRB@Performance+Measurement];
initial value: `[]`.
- `:MEASURE_PROC`: Procs for
{performance measurement}[rdoc-ref:IRB@Performance+Measurement];
initial value:
{
:TIME=>#