Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to start off by saying... I really don't need to be using 1.9.2. I understand that you don't ever, ever use Python 3.2, so if the common advice is that I should use 1.8, I'll do that. But don't tell me to do that because it's easier.

Whatever version I should be using, though, the question is still relevant: What's a good way to make one command do another command?

(I suppose I could write a c program to launch ruby1.9.1, call the executable ruby, and put it in my bin, but this seems like less than a good idea)

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

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 
share|improve this answer
1  
Is this a shell script? I have no idea how to work one of those... I tried copying the lines into the command line. This did not work. Help, what do I do. –  Daniel Aug 9 '11 at 13:18
add comment

Here is another question along the same vein: How do you uninstall Ruby 1.8.7 and install Ruby 1.9.2?

It's solution is to run the following command:

sudo update-alternatives --config ruby

Then you will get this output:

   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]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.