我想降低我在ubuntu 10.04os上安装的ruby版本(ruby 1.9.2),这样我就可以使用ruby 1.8.7的适当版本来运行rails 2.0.2。我正在使用旧版本的rails进行项目。
如果我将rails 2.0.2与ruby 1.9.2结合使用,它会给我一个错误,告诉我不能将枚举数转换成数组。
我想我可以用rvm,但我不确定它是否适合降级。
当我使用命令rvm list known时,在终端中得到以下信息
mgj@pc146724-desktop:~$ rvm list known
# MRI Rubies
[ruby-]1.8.6[-p399]
[ruby-]1.8.6-head
[ruby-]1.8.7[-p302]
[ruby-]1.8.7-head
[ruby-]1.9.1-p243
[ruby-]1.9.1[-p376]
[ruby-]1.9.1-p429
[ruby-]1.9.1-head
[ruby-]1.9.2-preview1
[ruby-]1.9.2-preview3
[ruby-]1.9.2-rc1
[ruby-]1.9.2-rc2
[ruby-]1.9.2[-p0]
[ruby-]1.9.2-head
ruby-head
# JRuby
jruby-1.2.0
jruby-1.3.1
jruby-1.4.0
jruby-1.5.1
jruby-1.5.2
/home/mohnish/.rvm/config/known
在使用命令dpkg-l grep ruby安装的ruby包列表中,我得到了以下内容
mgj@pc146724-desktop:~$ dpkg -l | grep ruby
ii libdbm-ruby 4.2 DBM interface for Ruby
ii libdbm-ruby1.8 1.8.7.249-2 DBM interface for Ruby 1.8
ii libgdbm-ruby 4.2 GDBM interface for Ruby
ii libgdbm-ruby1.8 1.8.7.249-2 GDBM interface for Ruby 1.8
ii libopenssl-ruby 4.2 OpenSSL interface for Ruby
ii libopenssl-ruby1.8 1.8.7.249-2 OpenSSL interface for Ruby 1.8
ii libreadline-ruby 4.2 Readline interface for Ruby
ii libreadline-ruby1.8 1.8.7.249-2 Readline interface for Ruby 1.8
ii libruby1.8 1.8.7.249-2 Libraries necessary to run Ruby 1.8
ii libtcltk-ruby 4.2 Tcl/Tk interface for Ruby
ii libtcltk-ruby1.8 1.8.7.249-2 Tcl/Tk interface for Ruby 1.8
ii rdoc 4.2 Generate documentation from ruby source file
ii ruby 4.2 An interpreter of object-oriented scripting
ii ruby-elisp 4.2 Emacs-lisp ruby-mode for Ruby
ii ruby-full 4.2 Ruby full installation
ii ruby1.8 1.8.7.249-2 Interpreter of object-oriented scripting lan
ii ruby1.8-dev 1.8.7.249-2 Header files for compiling extension modules
ii ruby1.8-elisp 1.8.7.249-2 ruby-mode for Emacsen
mgj@pc146724-desktop:~$ ^C
我需要卸载Ruby1.9.2,然后才刚刚安装Ruby1.8.7,还是可以切换版本?。如果我可以切换版本,请告诉我如何设置从Ruby1.9.2到Ruby1.8.7的路径。或者如果有别的办法请告诉我。
如果我必须卸载Ruby1.9.2,然后重新安装Ruby1.8.7,请告诉我该怎么做。我尝试了以下命令来卸载Ruby1.9.2,但是它似乎没有找到Ruby1.9.2包。
sudo aptitude remove ruby
sudo aptitude remove ruby 1.9.2p0
sudo purge ruby
sudo aptitude purge ruby 1.9.2p0
当我检查当前安装的ruby版本时,它显示:
mgj@pc146724-desktop:~/Downloads/rubygems_postextract/rubygems-1.4.1$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
mgj@pc146724-desktop:~/Downloads/rubygems_postextract/rubygems-1.4.1$ which ruby
/home/mgj/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
谢谢你的帮助!!
最佳答案
rvm的全部意义在于,您可以拥有多个版本的ruby,并且可以轻松地在它们之间切换。
rvm install 1.8.7 #or some specific version - choose from the rvm list known
rvm use 1.8.7
rvm gemset create rails202 #create a gemset called "rails202" for Ruby 1.8.7
rvm 1.8.7@rails202 #make the gemset the current selection
gem install rails -v 2.0.2 #install rails (just for this gemset!)
#now, we have a gemset called "rails202" in Ruby 1.8.7.
#anytime we want to use it, we do:
rvm 1.8.7@rails202
#create as many gemsets needed, eg for rails 3.0.3 on Ruby 1.8.7 we can do the
#similar as above. Then to use the new gemset just do:
rvm 1.8.7@rails303
#et voila! we are now using Rails 3.0.3 on Ruby 1.8.7 !