如何切换到旧版本的rails

时间:2023-01-17 09:31:40

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。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 **$ 

4 个解决方案

#1


24  

First, uninstall the version of Rails you have:

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

gem uninstall rails

rails gem卸载

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

接下来,安装您想要的Rails版本,如下所示:

gem install rails -v 3.1.12

gem安装rails - v3.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

#2


6  

I accidentally installed rails version 4.1.7 but our project need rails version 4.1.6 after it I uninstalled rails with this command:

我不小心安装了rails版本4.1.7,但是我们的项目需要rails版本4.1.6,因为我没有安装这个命令:

gem uninstall rails

rails gem卸载

and then install rails version 4.1.6 with this command:

然后使用以下命令安装rails 4.1.6版本:

gem install rails -v 4.1.6

gem安装rails - v4.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 in that list exist package that name is railties (4.1.7, 4.1.6) after it I removed it with this command :

通过运行gem列表,我在该列表中看到名为railties(4.1.7, 4.1.6)的存在包,我使用以下命令删除了它:

# gem uninstall railties

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

I input 2 and gem uninstall it. after it when I try rails -v I gave 4.1.6

我输入2,然后gem卸载它。之后当我尝试rails -v时,我给出了4。1.6

#3


2  

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 use whichever one you want to.

然后,您将只在该gemset中安装gem。我也很想为rails4制作一套宝石,而不是那些没有宝石的宝石。然后在它们之间切换你只要rvm gemset用你想要的任何一个。

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.

这里有更多关于gemset的内容,在rvmrc上也值得一读,因为这样你甚至不用切换gemsets。

#4


1  

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:

  • 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”(这意味着:它打开rails的最高版本,该版本存在于ruby gems中)
  • replace it with specific rails version as ----- version = "4.2.6"
  • 用特定的rails版本替换它,如--- version = "4.2.6"

In Linux:

  • goto ruby lib folder (in my system ---/.rvm/gems/ruby-2.3.1/bin)
  • goto 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) )

(给出了找到你的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 /珠宝/ 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版本。

#1


24  

First, uninstall the version of Rails you have:

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

gem uninstall rails

rails gem卸载

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

接下来,安装您想要的Rails版本,如下所示:

gem install rails -v 3.1.12

gem安装rails - v3.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

#2


6  

I accidentally installed rails version 4.1.7 but our project need rails version 4.1.6 after it I uninstalled rails with this command:

我不小心安装了rails版本4.1.7,但是我们的项目需要rails版本4.1.6,因为我没有安装这个命令:

gem uninstall rails

rails gem卸载

and then install rails version 4.1.6 with this command:

然后使用以下命令安装rails 4.1.6版本:

gem install rails -v 4.1.6

gem安装rails - v4.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 in that list exist package that name is railties (4.1.7, 4.1.6) after it I removed it with this command :

通过运行gem列表,我在该列表中看到名为railties(4.1.7, 4.1.6)的存在包,我使用以下命令删除了它:

# gem uninstall railties

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

I input 2 and gem uninstall it. after it when I try rails -v I gave 4.1.6

我输入2,然后gem卸载它。之后当我尝试rails -v时,我给出了4。1.6

#3


2  

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 use whichever one you want to.

然后,您将只在该gemset中安装gem。我也很想为rails4制作一套宝石,而不是那些没有宝石的宝石。然后在它们之间切换你只要rvm gemset用你想要的任何一个。

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.

这里有更多关于gemset的内容,在rvmrc上也值得一读,因为这样你甚至不用切换gemsets。

#4


1  

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:

  • 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”(这意味着:它打开rails的最高版本,该版本存在于ruby gems中)
  • replace it with specific rails version as ----- version = "4.2.6"
  • 用特定的rails版本替换它,如--- version = "4.2.6"

In Linux:

  • goto ruby lib folder (in my system ---/.rvm/gems/ruby-2.3.1/bin)
  • goto 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) )

(给出了找到你的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 /珠宝/ 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版本。