LinuxCommandLibrary

chruby

Change current Ruby version

SYNOPSIS

# Typically used after sourcing chruby.sh in your shell profile:
chruby [RUBY_VERSION]
chruby auto
chruby none
chruby --list | -l
chruby --version | -v
chruby --help | -h

PARAMETERS

RUBY_VERSION
    Switch to the specified Ruby version (e.g., chruby ruby-3.2.2). When no arguments are given, lists available Ruby versions.

auto
    Automatically switch to the Ruby version specified in a .ruby-version file found in the current directory or its parent directories.

none
    Unset the current Ruby version, effectively removing it from your PATH and restoring your system's default environment.

--list, -l
    Display a list of all detected Ruby versions that chruby can manage.

--version, -v
    Print the version of chruby itself.

--help, -h
    Show the command's help message, detailing usage and options.

DESCRIPTION

chruby is a remarkably light and fast Ruby version manager. Unlike more comprehensive alternatives such as RVM or rbenv, chruby operates on a philosophy of simplicity and non-invasiveness. It doesn't use shims, modify existing shell commands, or constantly hook into your shell's functions. Instead, chruby works by intelligently adjusting your PATH and other environment variables when you explicitly invoke it or when its initialization script is sourced by your shell (e.g., in .bashrc or .zshrc). This design minimizes overhead, making it exceptionally quick to switch between different Ruby installations. It seamlessly integrates with Rubies installed via ruby-build, rbenv install, or even custom-compiled versions, provided they adhere to expected directory structures. Its straightforward approach makes it an ideal choice for developers prioritizing speed and a clear, understandable environment.

CAVEATS

chruby operates as a shell function and must be sourced into your shell environment (e.g., .bashrc, .zshrc) to function correctly. It does not persist Ruby versions across shell sessions without this setup. chruby does not provide native gemset management; users typically rely on companion tools like chruby-gemset or Bundler for this functionality. By design, it avoids shims, which means some commands might require re-hashing in your shell after a switch or may not be found if their location is not properly added to PATH by the Ruby installation.

INSTALLATION & SETUP

chruby is typically installed by cloning its Git repository or via package managers like Homebrew on macOS. To make it functional, its main script (chruby.sh) must be sourced in your shell's configuration file (e.g., echo "source /usr/local/share/chruby/chruby.sh" >> ~/.bashrc). This makes the chruby function available in your shell.

RUBY DISCOVERY MECHANISM

chruby automatically detects installed Ruby versions by scanning predefined directories such as /opt/rubies/, ~/.rubies/, and /usr/local/rubies/. Each subdirectory within these paths is expected to contain a complete Ruby installation (e.g., ruby-3.2.2). This convention-over-configuration approach simplifies its setup and usage significantly.

HISTORY

chruby was created by Aaron Patterson (Postmodern) with the primary goal of providing a simpler, faster, and less intrusive alternative to existing Ruby version managers like RVM and rbenv. Its development focused on a minimalistic design, avoiding shell "shims" and complex hooks, which often added overhead to shell operations. By relying purely on modifying environment variables upon explicit invocation, chruby offers significantly faster Ruby switching and a cleaner shell environment, quickly gaining traction within the Ruby community for its performance and ease of use.

SEE ALSO

ruby-build(1), rvm(1), rbenv(1), gem(1), bash(1), zsh(1)

Copied to clipboard