Home > Uncategorized > Multiple Ruby with update-alternatives

Multiple Ruby with update-alternatives

Here’s a useful piece from David Lee on the Rails Oceania Google Group:

If any of you are using Ubuntu this is a pretty nice way to manage multiple ruby interpreters.

It has the advantage of managing the manpages, ri, and irb as “slaves”, so they change when a new interpreter is selected.

here’s the code:

# become root
su

# make sure the packages are installed for 1.8 & 1.9 aptitude install -s  ~n^ruby1.[89]$ ~n^irb1.[89]$ ~n^ri1.[89]

# install ruby1.8 & friends with priority 500
# so this will be the default “auto” choice
update-alternatives –install /usr/bin/ruby ruby /usr/bin/ruby1.8 500
–slave   /usr/share/man/man1/ruby.1.gz ruby.1.gz
/usr/share/man/man1/ruby.1.8.gz
–slave   /usr/bin/ri ri /usr/bin/ri1.8
–slave   /usr/bin/irb irb /usr/bin/irb1.8

# install ruby1.9 & friends with priority 400
update-alternatives –install /usr/bin/ruby ruby /usr/bin/ruby1.9 400
–slave   /usr/share/man/man1/ruby.1.gz ruby.1.gz
/usr/share/man/man1/ruby.1.9.gz
–slave   /usr/bin/ri ri /usr/bin/ri1.9
–slave   /usr/bin/irb irb /usr/bin/irb1.9

# choose your interpreter
# changes symlinks for /usr/bin/ruby ,
# /usr/bin/irb, /usr/bin/ri and man (1) ruby
update-alternatives –config ruby

for those with additional interpreters in say /usr/local/bin, other Debian variants, or managing other tools, vary as required.

% man update-alternatives

hope wrapping didn’t mangle it too much, and that someone finds this useful

Link to original here.

Categories: Uncategorized Tags:
  1. December 12th, 2009 at 04:59 | #1

    Thanks, that was useful. Something seems to be replacing a double-hyphen with a single dash, though, which breaks copy/pastability of the commandlines

  2. December 26th, 2009 at 18:32 | #2

    This worked like a charm. I’ve tried about 5 different solutions for utilizing multiple versions of ruby, and this one is the best.

  3. Darren
    December 5th, 2012 at 13:03 | #3

    This worked for me, with a few tweaks, on “Ubuntu 12.04.1 LTS”. This is the tweaked version:

    # make sure the packages are installed for 1.8 & 1.9
    sudo apt-get install -s ^ruby1.[89] ^irb1.[89] ^ri1.[89]

    # install ruby1.8 & friends with priority 500
    # so this will be the default “auto” choice
    sudo update-alternatives –install /usr/bin/ruby ruby /usr/bin/ruby1.8 500
    –slave /usr/share/man/man1/ruby.1.gz ruby.1.gz /usr/share/man/man1/ruby1.8.1.gz
    –slave /usr/bin/ri ri /usr/bin/ri1.8
    –slave /usr/bin/irb irb /usr/bin/irb1.8

    # install ruby1.9 & friends with priority 400
    sudo update-alternatives –install /usr/bin/ruby ruby /usr/bin/ruby1.9.1 400
    –slave /usr/share/man/man1/ruby.1.gz ruby.1.gz /usr/share/man/man1/ruby1.9.1.1.gz
    –slave /usr/bin/ri ri /usr/bin/ri1.9.1
    –slave /usr/bin/irb irb /usr/bin/irb1.9.1

    # choose your interpreter
    # changes symlinks for /usr/bin/ruby ,
    # /usr/bin/irb, /usr/bin/ri and man (1) ruby
    sudo update-alternatives –config ruby

  4. Darren
    December 5th, 2012 at 14:15 | #4

    This worked for me, with a few tweaks, on “Ubuntu 12.04.1 LTS”; the tweaks are posted to:

    https://psdlw.users.sourceforge.net/wordpress/?p=334

  1. No trackbacks yet.