如何为一个项目设置默认的rails版本?

时间:2023-01-17 09:35:59

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.nomachete神像.com/2008/03/12/using-multiple versions-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版本设置为默认?

8 个解决方案

#1


28  

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

#2


4  

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)

我无法通过RailsInstaller在Windows 7上使用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

#3


3  

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

#4


3  

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 --default is 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 1.9.3@rails-3.2.3 --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/下创建gemset和相关文件夹。rvm/gems/第二行使用gemset作为相关文件夹上gemset (Rails 3.2.3)中指定版本的默认第三行安装。

This is my gems folder's contents:

这是我的gems文件夹的内容:

cache  ruby-1.9.3-p194  ruby-1.9.3-p194@global  ruby-1.9.3-p194@rails-3.2.3

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

祝你好运

#5


0  

In your config/environment.rb file, place this at the beginning for the old version:

在你的配置/环境。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 '

#6


0  

here is a general format example. feel free to modify as needed

这里有一个通用的格式示例。如果需要,请随意修改

    rvm use ruby-2.1.0@rails4.2

#7


0  

First create Gemfile in the project directory specifying the desired version of Rails and then use bundle exec rails... so that Bundler takes care of running the appropriate version of rails.

首先在项目目录中创建Gemfile,指定所需的Rails版本,然后使用bundle exec Rails…因此Bundler将负责运行rails的适当版本。

mkdir myapp
cd myapp
echo "source 'https://rubygems.org'" > Gemfile
echo "gem 'rails', '5.0.0.1'" >> Gemfile
bundle install

bundle exec rails new . --force --skip-bundle

For more read this.

读这篇文章。

#8


-3  

You first installed a rvm(rails version management) then type. rvm 1.2.1

首先安装rvm(rails版本管理),然后输入。rvm 1.2.1 "

#1


28  

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

#2


4  

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)

我无法通过RailsInstaller在Windows 7上使用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

#3


3  

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

#4


3  

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 --default is 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 1.9.3@rails-3.2.3 --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/下创建gemset和相关文件夹。rvm/gems/第二行使用gemset作为相关文件夹上gemset (Rails 3.2.3)中指定版本的默认第三行安装。

This is my gems folder's contents:

这是我的gems文件夹的内容:

cache  ruby-1.9.3-p194  ruby-1.9.3-p194@global  ruby-1.9.3-p194@rails-3.2.3

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

祝你好运

#5


0  

In your config/environment.rb file, place this at the beginning for the old version:

在你的配置/环境。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 '

#6


0  

here is a general format example. feel free to modify as needed

这里有一个通用的格式示例。如果需要,请随意修改

    rvm use ruby-2.1.0@rails4.2

#7


0  

First create Gemfile in the project directory specifying the desired version of Rails and then use bundle exec rails... so that Bundler takes care of running the appropriate version of rails.

首先在项目目录中创建Gemfile,指定所需的Rails版本,然后使用bundle exec Rails…因此Bundler将负责运行rails的适当版本。

mkdir myapp
cd myapp
echo "source 'https://rubygems.org'" > Gemfile
echo "gem 'rails', '5.0.0.1'" >> Gemfile
bundle install

bundle exec rails new . --force --skip-bundle

For more read this.

读这篇文章。

#8


-3  

You first installed a rvm(rails version management) then type. rvm 1.2.1

首先安装rvm(rails版本管理),然后输入。rvm 1.2.1 "