Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

113 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rb

Switch between installed Ruby versions.

$ rb @1.9.3 && ruby -v                           # activate '1.9.3' install
$ echo 'ree' > ./.ruby-version && rb && ruby -v  # activate current `.ruby-version` ('ree') install
$ rb @system && ruby -v                          # activate system install
$ rb help

What It Does...

Modifies env vars: switches versions by modifying the PATH, GEM_HOME and GEM_PATH env vars. To accomplish this, it...

Adds functions to your shell: these are needed to modify shell env vars and are used to activate and reset the env, and to implement the CLI.

.ruby-version files: supports specifying versions with .ruby-version files.

Auto mode: (optional) update the version when you cd to a directory containing a .ruby-version file (does not hook cd).

Tab completions: version string parameters, commands, etc.

Rubies

Each installed version of ruby should live in $HOME/.rubies/. Install versions any way you prefer; ruby-build is recommended.

Shims

rb installs lightweight shims (in $HOME/.rb/shims, added to your PATH by rb init) for every executable across your installed rubies. A shim resolves the correct version from the nearest .ruby-version at run time, so bare commands — ruby, bundle, rspec, rails, … — use the right version in any shell, including non-interactive ones (scripts, cron, AI agents) where prompt-based auto-activation never runs. No rb @ prefix required.

Regenerate shims with rb reshim. This runs automatically after gem install/bundle install (and similar), and on install. Run it manually after installing a new ruby. Use rb which COMMAND to see the real path a command resolves to, and rb resolve to see the version that applies in the current directory.

Install

Open a terminal and run this command (view source):

(installs to $HOME/.local/bin; set PREFIX to override, e.g. PREFIX=/usr/local)

$ curl -L https://raw.githubusercontent.com/redding/rb/main/install.sh | sh

Init

Add rb init to your shell startup script. This installs tab completions and enables modifying the env vars.

eval "$(rb init)"

Auto Mode

(optional) If you want automatic handling, add the --auto flag to the init. In addition to the normal init above, $PROMPT_COMMAND is updated to activate any new ruby version as you change directories. Again, this is optional.

eval "$(rb init --auto)"

Quiet Mode

By default, rb outputs a warning saying which version/source it activates. If you want to silence these warnings, add the --quiet flag to the init.

eval "$(rb init --quiet)"

Usage

$ rb help

System Ruby

$ rb @system

.ruby-version Files

If no explicit @ parameter is specified, rb will look for the version in a file named .ruby-version in your current directory, its parent directories, or your home directory. The .ruby-version files are expected to contain nothing but the version requested.

$ echo "1.9.3-p0" > $HOME/.ruby-version
$ cd $HOME && rb && ruby -v  # 1.9.3-p0

You can specify a specific version file using the -f option:

$ cd $HOME
$ echo 'ree-1.8.7-2012.02' > /a/path/to/.ruby-version
$ rb -f /a/path/to/.ruby-version
$ ruby -v # will use ree-1.8.7-2012.02

Note: You can specify a "default" version file at $HOME/.rubies/.ruby-version. This version will be used when no other .ruby-version can be found and no command line version has been specified.

Note: If an @<version> parameter is given, it will always override any versions specified in .ruby-version files.

Pow

Add a .ruby-version file to your project, as well as a .powrc file containing the following line (this will make Pow start up your project using the install in the version file):

source `which rb` && rb @

Uninstall

Open a terminal and run this command (view source):

$ curl -L https://raw.githubusercontent.com/redding/rb/main/uninstall.sh | sh

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Switch between installed Ruby versions.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages