我如何让“ruby”做“ruby1.9.1”的作用?

Dan*_*iel 7 ruby command-line

我想首先说...我真的不需要使用 1.9.2。我知道你永远不会使用 Python 3.2,所以如果普遍的建议是我应该使用 1.8,我会这样做。但不要告诉我这样做,因为它更容易。

但是,无论我应该使用什么版本,问题仍然是相关的:让一个命令执行另一个命令的好方法是什么?

(我想我可以编写 ac 程序来启动 ruby​​1.9.1,调用可执行文件 ruby​​,并将其放入我的 bin 中,但这似乎不是一个好主意)

Oli*_*Oli 7

首先,您不需要编写 C 应用程序 - 一个简单的 bash 小曲就可以了。

我认为最干净的解决方案将涉及update-alternatives系统。例如,这就是 Ubuntu 如何在彼此并排安装的情况下设法将各种 Java 虚拟机分开的方式。问题是你需要自己设置。

我刚刚看到一个邮件列表帖子,它似乎为您完成了大部分繁重的工作。您可能需要稍微更改版本号,但除此之外,您应该明白这一点。

对于后代(如果谷歌拒绝 URL 或线程),我现在会在业务端复制,但我不会因为写它而受到赞扬。

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 
Run Code Online (Sandbox Code Playgroud)


kri*_*anp 6

这里还有一个同样的问题: 如何卸载 Ruby 1.8.7 并安装 Ruby 1.9.2?

它的解决方案是运行以​​下命令:

sudo update-alternatives --config ruby
Run Code Online (Sandbox Code Playgroud)

然后你会得到这个输出:

   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]
Run Code Online (Sandbox Code Playgroud)