Ruby-on-rails 如何切换到旧版本的 rails

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17052629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:08:56  来源:igfitidea点击:

How to switch to an older version of rails

ruby-on-railsruby

提问by RyanWilcox

I'm trying to follow an older book written in 2011.

我正在尝试阅读 2011 年写的一本旧书。

So, randomly picked 3.1.3version 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.beta1version ...

目前有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 **$ 

回答by RyanWilcox

First, uninstall the version of Rails you have:

首先,卸载您拥有的 Rails 版本:

gem uninstall rails

gem uninstall rails

Next, install the version of Rails you want, like so:

接下来,安装所需的 Rails 版本,如下所示:

gem install rails -v 3.1.12

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. You could also install RVM- the Ruby enVironment Manager - and use separate gemsets to keep the two versions of Rails apart. But if you are just learning you may not want to bother with this.

有几种方法可以同时“安装”两者。正如 Joe Frambach 建议的那样,您可以在 VM 中安装 Rails 4。您还可以安装RVM- Ruby 环境管理器 - 并使用单独的 gemset 将两个版本的 Rails 分开。但是,如果您只是在学习,您可能不想为此烦恼。

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

回答by Esterlinkof

I accidentally installed rails version 4.1.7but I need rails version 4.1.6. In order to fix this issue I uninstalled rails with this command:

我不小心安装了 rails version4.1.7但我需要 rails version 4.1.6。为了解决这个问题,我使用以下命令卸载了 rails:

gem uninstall rails

gem uninstall rails

and install version 4.1.6 with:

并使用以下命令安装 4.1.6 版:

gem install rails -v 4.1.6

gem install rails -v 4.1.6

but when I run rails -vit's version still be 4.1.7.

但是当我运行rails -v它的版本仍然是4.1.7.

By running gem listI see that railties (4.1.7, 4.1.6)package exist in my gems. I removed it with below procedure and fix rails version problem.

通过运行,gem list我看到该railties (4.1.7, 4.1.6)包存在于我的 gem 中。我使用以下程序将其删除并修复了 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 并卸载 version 4.1.7

回答by Shadwell

You're already using RVM it seems. Create a gemset for the different rails versions:

您似乎已经在使用 RVM。为不同的 rails 版本创建一个 gemset:

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

You'll then only get the gems installed in that gemset. I'd be tempted to create a gemset for rails4 too rather than having gems kicking around that aren't in a gemset. Then to switch between them you just rvm gemset usewhichever one you want to.

然后,您只会在该 gemset 中安装 gem。我也很想为 rails4 创建一个 gemset,而不是让那些不在 gemset 中的 gem 到处乱跑。然后在它们之间切换,您可以rvm gemset use随意切换。

There's more about gemset hereand it'd be worth reading up on rvmrctoo because then you don't even have to switch gemsets.

还有更多的宝石在这里,它将会是值得阅读了rvmrc太多,因为你甚至不用切换gemsets。

回答by dathatreyaKV

We can change our default version of rails.
Rails version defined in Ruby "bin" itself.

我们可以更改 Rails 的默认版本。
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)
  • you will find "rails" file there
  • 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)
  • replace it with specific rails version as ----- version = "4.2.6"
  • 转到您当前的 ruby​​ 版本“bin”文件夹(在我的系统c:/RubyXX-x64/bin 中
  • 你会在那里找到“rails”文件
  • 用文本编辑器打开那个“rails”文件,你会看到 ----- version = ">= 0"(这意味着:它打开了你的 ruby​​ gem 中存在的最高版本的 rails)
  • 将其替换为特定的 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.

  • save and check your current rails version.

  • 将 ( verion = ">= 0" ) 替换为 ( verion = "4.2.6" ) 您的特定安装版本。

  • 保存并检查您当前的 rails 版本。