Well to start with, you wouldn't need to write a C application - a simple bash ditty would do you fine.
I think the cleanest possible solution would involve the update-alternatives
system. This is how, for example, Ubuntu manages to keep various Java virtual machines separated while installed alongside each other. The problem is you need to set it up yourself.
I just came across a mailing-list post that does seem to do most of the heavy lifting for you. You might need to change the version numbers slightly but other than that, you should get the idea.
For posterity (in case Google nixes the URL or the thread), I'll copy in the business end now but I take no credit for writing it.
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
...
--
cheers,
David Lee
Is there a problem with having both installed? And using the versions from the repositories? I would install ruby 1.9.2 with:
sudo apt-get install ruby1.9.1-full
And then update the "alternatives" system to use ruby 1.9:
$ sudo update-alternatives --config ruby
There are 2 choices for the alternative ruby (providing /usr/bin/ruby).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/ruby1.8 50 auto mode
1 /usr/bin/ruby1.8 50 manual mode
2 /usr/bin/ruby1.9.1 10 manual mode
Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/ruby1.9.1 to provide /usr/bin/ruby (ruby) in manual mode.
$ ruby --version
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
This will also set the alternatives for erb
, irb
, rdoc
, ri
, testrb
and the man page. However you need to update the gem command separately:
$ sudo update-alternatives --config gem
There are 2 choices for the alternative gem (providing /usr/bin/gem).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/gem1.8 180 auto mode
1 /usr/bin/gem1.8 180 manual mode
2 /usr/bin/gem1.9.1 10 manual mode
Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/gem1.9.1 to provide /usr/bin/gem (gem) in manual mode.
I know, it is confusingly called ruby1.9.1 rather than 1.9.2, some upstream debian packaging thing.
Best Answer
The 1.9.1 stands for the binary-compatibility version (and as you can read in the package description, ruby 1.9.2 is binary-compatible to ruby 1.9.1).
This is rather confusing - more explanations can be found here and here.