Changes the current Ruby.
- Also adds RubyGems
- Also adds RubyGems
- Correctly sets
- Users: gems are installed into
- Root: gems are installed directly into
- Users: gems are installed into
- Additionally sets
- Optionally sets
$RUBYOPTif second argument is given.
hash -rto clear the command-lookup hash-table.
- Fuzzy matching of Rubies by name.
- Defaults to the system Ruby.
- Optionally supports auto-switching and the
- Supports bash and zsh.
- Small (~90 LOC).
- Has tests.
- Does not hook
- Does not install executable shims.
- Does not require Rubies be installed into your home directory.
- Does not automatically switch Rubies by default.
- Does not require write-access to the Ruby directory in order to install gems.
wget -O chruby-0.3.8.tar.gz https://github.com/postmodern/chruby/archive/v0.3.8.tar.gz tar -xzvf chruby-0.3.8.tar.gz cd chruby-0.3.8/ sudo make install
wget https://raw.github.com/postmodern/chruby/master/pkg/chruby-0.3.8.tar.gz.asc gpg --verify chruby-0.3.8.tar.gz.asc chruby-0.3.8.tar.gz
chruby can also be installed with homebrew:
brew install chruby
Or the absolute latest chruby can be installed from source:
brew install chruby --HEAD
chruby is already included in the AUR:
yaourt -S chruby
chruby is included in the official FreeBSD ports collection:
cd /usr/ports/devel/chruby/ && make install clean
Chruby provides detailed instructions for installing additional Rubies:
You can also use ruby-install to install additional Rubies:
ruby-install ruby ruby-install jruby ruby-install rubinius ruby-install maglev
You can also use ruby-build to install additional Rubies:
ruby-build 1.9.3-p392 /opt/rubies/ruby-1.9.3-p392 ruby-build jruby-1.7.3 /opt/rubies/jruby-1.7.3 ruby-build rbx-2.0.0-rc1 /opt/rubies/rubinius-2.0.0-rc1 ruby-build maglev-1.0.0 /opt/rubies/maglev-1.0.0
Add the following to the
If you wish to enable chruby system-wide, add the following to
if [ -n "$BASH_VERSION" ] || [ -n "$ZSH_VERSION" ]; then source /usr/local/share/chruby/chruby.sh ... fi
This will prevent chruby from accidentally being loaded by
is not always the same as
When chruby is first loaded by the shell, it will auto-detect Rubies installed
~/.rubies/. After installing new Rubies, you must
restart the shell before chruby can recognize them.
For Rubies installed in non-standard locations, simply append their paths to
source /usr/local/share/chruby/chruby.sh RUBIES+=( /opt/jruby-1.7.0 "$HOME/src/rubinius" )
If you are migrating from another Ruby manager, set
If you want chruby to auto-switch the current version of Ruby when you
between your different projects, simply load
source /usr/local/share/chruby/chruby.sh source /usr/local/share/chruby/auto.sh
If you want to automatically run the version of a gem executable specified in your project's Gemfile, try rubygems-bundler.
If you wish to set a default Ruby, simply call
If you have enabled auto-switching, simply create a
echo "ruby-1.9" > ~/.ruby-version
Gems installed as a non-root user via
gem install will be installed into
~/.gem/$ruby/X.Y.Z. By default, RubyGems will use the absolute path to the
currently selected ruby for the shebang of any binstubs it generates. In some
cases, this path may contain extra version information (e.g.
ruby-2.0.0-p451). To mitigate potential problems when removing rubies, you
can force RubyGems to generate binstubs with shebangs that will search for
ruby in your
$PATH by using
gem install --env-shebang (or the equivalent
-E). This parameter can also be added to your gemrc file.
For instructions on using chruby with other tools, please see the wiki:
List available Rubies:
$ chruby ruby-1.9.3-p392 jruby-1.7.0 rubinius-2.0.0-rc1
Select a Ruby:
$ chruby 1.9.3 $ chruby * ruby-1.9.3-p392 jruby-1.7.0 rubinius-2.0.0-rc1 $ echo $PATH /home/hal/.gem/ruby/1.9.3/bin:/opt/rubies/ruby-1.9.3-p392/lib/ruby/gems/1.9.1/bin:/opt/rubies/ruby-1.9.3-p392/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/hal/bin:/home/hal/bin $ gem env RubyGems Environment: - RUBYGEMS VERSION: 1.8.23 - RUBY VERSION: 1.9.3 (2013-02-22 patchlevel 392) [x86_64-linux] - INSTALLATION DIRECTORY: /home/hal/.gem/ruby/1.9.3 - RUBY EXECUTABLE: /opt/rubies/ruby-1.9.3-p392/bin/ruby - EXECUTABLE DIRECTORY: /home/hal/.gem/ruby/1.9.3/bin - RUBYGEMS PLATFORMS: - ruby - x86_64-linux - GEM PATHS: - /home/hal/.gem/ruby/1.9.3 - /opt/rubies/ruby-1.9.3-p392/lib/ruby/gems/1.9.1 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - "gem" => "--no-rdoc" - REMOTE SOURCES: - http://rubygems.org/
Switch to JRuby in 1.9 mode:
$ chruby jruby --1.9 $ ruby -v jruby 1.7.0 (1.9.3p203) 2012-10-22 ff1ebbe on OpenJDK 64-Bit Server VM 1.7.0_09-icedtea-mockbuild_2012_10_17_15_53-b00 [linux-amd64]
Switch back to system Ruby:
$ chruby system $ echo $PATH /usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/hal/bin
Run a command under a Ruby with
$ chruby-exec jruby -- gem update
Switch to an arbitrary Ruby on the fly:
$ chruby_use /path/to/ruby
After removing the chruby configuration:
$ sudo make uninstall
* Deprecated in favor of chruby.
chrubyis nice, does the limited thing of switching really good, the only hope it never grows
I just looooove chruby For the first time I'm in total control of all aspects of my Ruby installation.
Written by Postmodern, it's basically the simplest possible thing that can work.
So far, I'm a huge fan. The tool does what it advertises exactly and simply. The small feature-set is also exactly and only the features I need.
I wrote ruby-version; however, chruby is already what ruby-version wanted to be. I've deprecated ruby-version in favor of chruby.