简体   繁体   English

如何切换到旧版本的 rails

[英]How to switch to an older version of rails

I'm trying to follow an older book written in 2011.我正在尝试阅读 2011 年写的一本旧书。

So, randomly picked 3.1.3 version since that's Nov 2011.所以,从 2011 年 11 月开始随机选择3.1.3版本。

How do I switch to that version in my RVM?如何在我的 RVM 中切换到该版本?

Currently have Rails 4.0.0.beta1 version ...目前有Rails 4.0.0.beta1版本...

Please don't suggest to put it in the Gemfile because there are a lot of other dependencies that will just be too troublesome to deal with, hence if I just switch, I'm assuming it means that other dependencies will be taken care of at the same time too, right?请不要建议将它放在 Gemfile 中,因为还有很多其他依赖项处理起来太麻烦,因此如果我只是切换,我假设这意味着其他依赖项将在也是同一时间吧?

UPDATE更新

**-s-MacBook-Pro:agile **$ rails -v
Rails 4.0.0.beta1
**-s-MacBook-Pro:agile **$ gem install rails -v 3.1.3
Successfully installed rails-3.1.3
1 gem installed
**-s-MacBook-Pro:agile **$ rvm gemset create rails 313
gemset created rails    => /Users/**/.rvm/gems/ruby-1.9.3-p392@rails
gemset created 313  => /Users/**/.rvm/gems/ruby-1.9.3-p392@313
**-s-MacBook-Pro:agile **$ ruby -v
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin10.8.0]
**-s-MacBook-Pro:agile **$ rvm 1.9.3p392-head@rails313
Unknown ruby interpreter version: '1.9.3p392'.
**-s-MacBook-Pro:agile **$ 

UPDATE AGAIN再次更新

**-s-MacBook-Pro:agile **$ rvm gemset use 313
Using ruby-1.9.3-p392 with gemset 313
**-s-MacBook-Pro:agile **$ rails -v
/Library/Ruby/Site/1.8/rubygems/dependency.rb:296:in `to_specs': Could not find 'rails'     (>= 0) among 2 total gem(s) (Gem::LoadError)
from /Library/Ruby/Site/1.8/rubygems/dependency.rb:307:in `to_spec'
from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_gem.rb:47:in `gem'
from /usr/bin/rails:18
**-s-MacBook-Pro:agile **$ 

First, uninstall the version of Rails you have:首先,卸载您拥有的 Rails 版本:

gem uninstall rails

Next, install the version of Rails you want, like so:接下来,安装所需的 Rails 版本,如下所示:

gem install rails -v 3.1.12

There are a few ways to have both "installed" at the same time.有几种方法可以同时“安装”两者。 As Joe Frambach suggested, you could install Rails 4 in a VM.正如 Joe Frambach 建议的那样,您可以在 VM 中安装 Rails 4。 You could also install RVM - the Ruby enVironment Manager - and use separate gemsets to keep the two versions of Rails apart.您还可以安装RVM - Ruby 环境管理器 - 并使用单独的 gemset 将两个版本的 Rails 分开。 But if you are just learning you may not want to bother with this.但是,如果您只是在学习,您可能不想为此烦恼。

Edit: @Shadwell's answer got it right, although it could use some expansion, which I'll do here:编辑: @Shadwell 的回答是正确的,虽然它可以使用一些扩展,我将在这里做:

> rvm gemset create rails3
> rvm gemset use rails3
> gem install rails -v 3.1.12
> rails my_new_app

I accidentally installed rails version 4.1.7 but I need rails version 4.1.6 .我不小心安装了 rails 版本4.1.7但我需要 rails 版本4.1.6 In order to fix this issue I uninstalled rails with this command:为了解决这个问题,我使用以下命令卸载了 rails:

gem uninstall rails

and install version 4.1.6 with:并使用以下命令安装 4.1.6 版:

gem install rails -v 4.1.6

but when I run rails -v it's version still be 4.1.7 .但是当我运行rails -v它的版本仍然是4.1.7

By running gem list I see that railties (4.1.7, 4.1.6) package exist in my gems.通过运行gem list我看到我的 gems 中存在railties (4.1.7, 4.1.6)包。 I removed it with below procedure and fix rails version problem.我使用以下程序将其删除并修复了 rails 版本问题。

$ gem uninstall railties

Select gem to uninstall:
 1. railties-4.1.6
 2. railties-4.1.7
 3. All versions
>

Input 2 and uninstall version 4.1.7 .输入 2 并卸载版本4.1.7

You're already using RVM it seems.您似乎已经在使用 RVM。 Create a gemset for the different rails versions:为不同的 rails 版本创建一个 gemset:

> rvm gemset create rails3
> rvm gemset use rails3
> bundle install

You'll then only get the gems installed in that gemset.然后,您只会在该 gemset 中安装 gem。 I'd be tempted to create a gemset for rails4 too rather than having gems kicking around that aren't in a gemset.我也很想为 rails4 创建一个 gemset,而不是让那些不在 gemset 中的 gem 到处乱跑。 Then to switch between them you just rvm gemset use whichever one you want to.然后要在它们之间切换,您只需rvm gemset use您想要的任何一个。

There's more about gemset here and it'd be worth reading up on rvmrc too because then you don't even have to switch gemsets.还有更多的宝石在这里,它将会是值得阅读了rvmrc太多,因为你甚至不用切换gemsets。

We can change our default version of rails.我们可以更改 Rails 的默认版本。
Rails version defined in Ruby "bin" itself. Ruby“bin”本身定义的Rails版本。

install required rails version by通过以下方式安装所需的 Rails 版本

gem install rails -v 4.2.6

and

In Windows:在 Windows 中:

  • goto your current ruby version 'bin' folder ( in my system c:/RubyXX-x64/bin )转到您当前的 ruby​​ 版本“bin”文件夹(在我的系统c:/RubyXX-x64/bin 中
  • you will find "rails" file there你会在那里找到“rails”文件
  • open that "rails" file with text editor you will see ----- version = ">= 0" (which means: it opens the highest version of rails, which exist in your ruby gems)用文本编辑器打开那个“rails”文件,你会看到 ----- version = ">= 0" (这意味着:它打开了你的 ruby​​ gem 中存在的最高版本的 rails)
  • replace it with specific rails version as ----- version = "4.2.6"将其替换为特定的 rails 版本 ----- version = "4.2.6"

In Linux:在 Linux 中:

  • goto ruby lib folder (in my system ---/.rvm/gems/ruby-2.3.1/bin)转到 ruby​​ lib 文件夹(在我的系统中 ---/.rvm/gems/ruby-2.3.1/bin)

$ which bundle $哪个捆绑

(gives path to find from which ruby your bundler executing( ---/.rvm/gems/ruby-2.3.1/bin/bundler) ) (给出了查找打包程序从哪个 ruby​​ 执行的路径(---/.rvm/gems/ruby-2.3.1/bin/bundler))

  • edit "rails" file with your text editor使用文本编辑器编辑“rails”文件

dathu@ubuntu:~/.rvm/gems/ruby-2.3.1/bin$ sudo subl rails dathu@ubuntu:~/.rvm/gems/ruby-2.3.1/bin$ sudo subl rails

  • replace ( verion = ">= 0" ) with ( verion = "4.2.6" ) your specific installed version.将 ( verion = ">= 0" ) 替换为 ( verion = "4.2.6" ) 您的特定安装版本。

  • save and check your current rails version.保存并检查您当前的 rails 版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM