Ruby-on-rails 如何为项目设置默认 rails 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6148308/
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
How to set default rails version for a project?
提问by Mr. Black
I have installed two different rails versions in my system (Fedora).
我在我的系统 (Fedora) 中安装了两个不同的 Rails 版本。
gem list -d rails
*** LOCAL GEMS ***
rails (3.0.5, 1.2.1)
Author: David Heinemeier Hansson
Rubyforge: http://rubyforge.org/projects/rails
Homepage: http://www.rubyonrails.org
Installed at (3.0.5): /usr/local/lib/ruby/gems/1.8
(1.2.1): /usr/local/lib/ruby/gems/1.8
Full-stack web application framework.
When i try to create the project like following way ("http://www.nomachetejuggling.com/2008/03/12/using-multiple-versions-of-rails/")
当我尝试像以下方式创建项目时(“ http://www.nomachetejuggling.com/2008/03/12/using-multiple-versions-of-rails/”)
rails 1.2.1 myproject
But, it's not working. So, i checked
但是,它不起作用。所以,我检查了
rails -v
Rails 3.0.5
So, can you help me, how to create the project with older version and newer version. Is there any way to set the particular rails version as default?
所以,你能帮我,如何用旧版本和新版本创建项目。有没有办法将特定的 rails 版本设置为默认版本?
回答by matkins
To use an older version than the latest you have installed, just wrap the version number in underscores:
要使用比您安装的最新版本旧的版本,只需将版本号用下划线括起来:
rails _1.2.1_ myproject
rails _1.2.1_ myproject
回答by sameers
I couldn't get matkins' answer to work via RailsInstaller on Windows 7, so I thought I'd post my solution for someone else to benefit from: (I don't have the reputation to offer this as a comment so I'm adding a new answer)
我无法通过 Windows 7 上的 RailsInstaller 获得 matkins 的答案,所以我想我会发布我的解决方案让其他人从中受益:(我没有将其作为评论提供的声誉,所以我添加新答案)
c:\>rails -v
Rails 4.0.0
c:\>rails _3.2.8_ app1 &REM This is going to bug out
Instead, I found this works:
相反,我发现这有效:
c:\>rails _3.2.8_ new app1 &REM This will work
回答by fx_
The URL you posted solves your problem - you simply forgot the underscores.
您发布的 URL 解决了您的问题 - 您只是忘记了下划线。
varar:~ mr$ gem list rails
*** LOCAL GEMS ***
rails (3.1.0.rc1, 3.1.0.beta1, 3.0.3, 3.0.1)
varar:~ mr$ rails _3.0.1_ -v
Rails 3.0.1
回答by S.M.Mousavi
As @Shaun mentioned in this post, you can use multiple versions of Rails and Ruby in same time!
For using an specific version of ruby:
正如@Shaun 在这篇文章中提到的,您可以同时使用多个版本的 Rails 和 Ruby!
使用特定版本的 ruby:
rvm use 1.9.3 --default
Switch --defaultis used for setting this version as Ruby default version.
For using an specific Rails and Ruby version:
Switch--default用于将此版本设置为 Ruby 默认版本。
使用特定的 Rails 和 Ruby 版本:
rvm gemset create rails-3.2.3
rvm use [email protected] --default
gem install rails
First line creates a gemset and related folder under /home/username/.rvm/gems/
Second line use that gemset as default one
Third line install specified version in gemset (Rails 3.2.3) on related folder.
第一行在/home/username/.rvm/gems/
第二行下创建一个 gemset 和相关文件夹,使用该 gemset 作为默认
第三行在相关文件夹上的 gemset (Rails 3.2.3) 中安装指定版本。
This is my gemsfolder's contents:
这是我gems文件夹的内容:
cache ruby-1.9.3-p194 ruby-1.9.3-p194@global [email protected]
Initial folder is ruby-1.9.3-p194@global. Therefore for backing to previous state, just run:
初始文件夹是ruby-1.9.3-p194@global. 因此,要回到以前的状态,只需运行:
rvm use 1.9.3@global
and you can see previous Rails and Ruby versions :)
你可以看到以前的 Rails 和 Ruby 版本:)
Good luck
祝你好运
回答by Sawo Cliff
here is a general format example. feel free to modify as needed
这是一个通用格式示例。可以根据需要随意修改
rvm use [email protected]
回答by Chris Bunch
In your config/environment.rbfile, place this at the beginning for the old version:
在您的config/environment.rb文件中,将其放在旧版本的开头:
RAILS_GEM_VERSION = '1.2.1'
RAILS_GEM_VERSION = '1.2.1'
or this for the new version:
或者对于新版本:
RAILS_GEM_VERSION = '3.0.5'
RAILS_GEM_VERSION = '3.0.5'
回答by User123
You first installed a rvm(rails version management) then type. rvm 1.2.1
您首先安装了 rvm(rails 版本管理)然后键入。房车 1.2.1

