我用Ruby 2.0创建了Rails 4项目。 如何暂时将Ruby的版本更改为1.9.3。
我尝试在Gemfile中添加一行:
ruby "1.9.3"
但是当我运行rake任务时,它显示:
/home/askar/.rvm/gems/ruby-2.0.0-p195@global/gems/bundler-1.3.5/lib/bundler/definition.rb:361:in `validate_ruby!': Your Ruby version is 2.0.0, but your Gemfile specified 1.9.3 (Bundler::RubyVersionMismatch)
from /home/askar/.rvm/gems/ruby-2.0.0-p195@global/gems/bundler-1.3.5/lib/bundler.rb:116:in `setup'
from /home/askar/.rvm/gems/ruby-2.0.0-p195@global/gems/rubygems-bundler-1.2.0/lib/rubygems-bundler/noexec.rb:73:in `setup'
from /home/askar/.rvm/gems/ruby-2.0.0-p195@global/gems/rubygems-bundler-1.2.0/lib/rubygems-bundler/noexec.rb:85:in `<top (required)>'
from /home/askar/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:110:in `require'
from /home/askar/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:110:in `rescue in require'
from /home/askar/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:35:in `require'
from /home/askar/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:9:in `<main>'
答案 0 :(得分:3)
您应该使用rvm
。输入您的控制台:
rvm install 1.9.3 # if you don't have appropriate version installed
rvm use 1.9.3
然后你应该运行
bundle
安装你的宝石(这是因为切换到1.9.3
后的本地宝石将是空的)它应该可以工作。
答案 1 :(得分:2)
为您的项目创建.rvmrc文件
在应用程序的根目录下运行命令
rvm use 1.9.3@rails3 --create --rvmrc
所以每当你进入项目目录时,ruby版本将改为1.9.3并将使用gemset'rail3'。