/switch-ruby

A script that lets you easily switch the current version of ruby

Primary LanguageRuby

switch-ruby

Usage

$ switch-ruby
Usage: /Users/cpetschnig/bin/switch-ruby [OPTION]... [Ruby Version index]

Available Ruby Versions:

1.  RUBY_VERSION      => 2.0.0
    RUBY_DESCRIPTION  => ruby 2.0.0p247 (2013-06-27) [x86_64-darwin13.0.0]
    Location          => /Users/cpetschnig/.rb/ruby-2.0.0-p247

2.  RUBY_VERSION      => 1.9.3
    RUBY_DESCRIPTION  => ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-darwin13.0.0]
    Location          => /Users/cpetschnig/.rb/ruby-1.9.3-p484

OPTIONS:
-h, --help       Show this message
-v, --verbose    Be more chatty

$ switch-ruby 1
You are now using ruby 2.0.0p247 (2013-06-27) [x86_64-darwin13.0.0]

Preparing your System

Create a directory, that will contain a symbolic link to your ruby /bin folder, where all Ruby executables lie:

$ mkdir ~/.rb

Create a directory where you put your Ruby source files into:

$ mkdir ~/.rb/src

I prefer to leave all ruby-0.0.0-p000.tar.gz in the /cache directory:

$ mkdir ~/.rb/cache

Now make sure it will be the first directory when looking for executables. Put the following line in your /etc/profile or ~/.bash.rc files:

export PATH=$HOME/.rb/bin:$PATH

Make your switch-ruby file executable on your system. You should know how to do this by youself.

Installing a new Ruby

Download the Ruby source and put it into the ~/.rb/cache folder:

$ cd ~/.rb/cache
$ wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz

Extract it to the ~/.rb/src folder:

$ cd ~/.rb/src
$ tar xzvf ../cache/ruby-2.0.0-p353.tar.gz

Build and install Ruby:

$ ./configure --prefix=$HOME/.rb/ruby-2.0.0-p353
$ make
$ make install

The new Ruby will now be listed when you run

$ switch-ruby

Command Line Arguments

-h, --help Show a help message

-v, --verbose Gives a lot of information what the program is doing

License

Copyright © 2009 Christoph Petschnig

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.