Skip to content

mpapis/chruby

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chruby

Simple Ruby switcher.

Features

  • Simply modifies $PATH.
  • Correctly sets $GEM_HOME and $GEM_PATH.
    • Users: gems are installed into ~/.gem/$ruby/$version.
    • Root: gems are installed directly into /path/to/$ruby/$gemdir.
  • Adds RubyGems bin/ directories to $PATH.
  • Optionally sets $RUBYOPT is a second argument is given.
  • Additionally sets $RUBY, $RUBY_ENGINE, $RUBY_VERSION and $GEM_ROOT.
  • Calls hash -r to clear the command-lookup hash-table.
  • Fuzzy matching of Rubies by name.
  • Defaults to the system Ruby.
  • Small (~80 LOC).

Anti-Features

  • Does not hook cd.
  • Does not install executable shims.
  • Does not require Rubies be installed into your home directory.
  • Does not automatically switch Rubies upon login or when changing directories.
  • Does not require write-access to the Ruby directory in order to install gems.

Install

wget http://cloud.github.com/downloads/postmodern/chruby/chruby-0.1.0.tar.bz2
tar -xjvf chruby-0.1.0.tar.bz2
cd chrub-0.1.0/
make install

PGP

All releases are PGP signed for security. Instructions on how to import my PGP key can be found on my blog. To verify that a release was not tampered with:

wget http://cloud.github.com/downloads/postmodern/chruby/chruby-0.1.0.tar.bz2.asc
gpg --verify chruby-0.1.0.tar.bz2.asc chruby-0.1.0.tar.bz2

Configuration

Add the following lines to your ~/.bashrc or ~/.profile file:

. /usr/local/etc/profile.d/chruby.sh

RUBIES=~/src/{ruby,jruby,rubinius}*

System Wide

Create a /etc/profile.d/chruby.sh file, containing the following:

. /usr/local/etc/profile.d/chruby.sh

RUBIES=(
  /usr/local/ruby-1.8.7-p370
  /usr/local/ruby-1.9.3-p194
  /usr/local/jruby-1.6.7.2
  /usr/local/rubinius
)

Examples

List available Rubies:

$ chruby
   ruby-1.8.7-p370
   ruby-1.9.3-p194
   jruby-1.6.7.2
   rubinius

Select a Ruby:

$ chruby 1.8
$ chruby
 * ruby-1.8.7-p370
   ruby-1.9.3-p194
   jruby-1.6.7.2
   rubinius
$ echo $PATH
/home/hal/.gem/ruby/1.8.7/bin:/usr/local/ruby-1.8.7-p370/lib/ruby/gems/1.8/bin:/usr/local/ruby-1.8.7-p370/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/hal/bin
$ echo $GEM_HOME
/home/hal/.gem/ruby/1.8.7
$ echo $GEM_PATH
/home/hal/.gem/ruby/1.8.7:/usr/local/ruby-1.8.7-p370/lib/ruby/gems/1.8

Switch to JRuby in 1.9 mode:

$ chruby jruby --1.9
$ ruby -v
jruby 1.6.7.2 (ruby-1.9.2-p312) (2012-05-01 26e08ba) (OpenJDK 64-Bit Server VM 1.6.0_24) [linux-amd64-java]

Switch back to system Ruby:

$ chruby system
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/hal/bin

Switch to an arbitrary Ruby on the fly:

$ chruby_use /path/to/ruby

Alteratives

About

Simple Ruby switcher

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 100.0%