简体   繁体   中英

How can I install different versions of Rails and keep the existing ones?

I had Rails 2.3.5 installed, and wanted to upgrade to 2.3.10 as a stepping stone to Rails 3. I thought running gem install rails -v=2.3.10 would install 2.3.10 and keep 2.3.5 as well. But now when I do rails -v , it only lists Rails 2.3.10. How can I install different versions of Rails and keep the existing ones?

gem list rails should show you all installed versions of Rails. You can specify which one you want each project to use in the config/environment.rb file.

Alternately (or "additionally"), look in to RVM (particularly the "gemset" function) for maintaining separate gem sets for each project.

Updated May 2017 Instead of RVM gemsets, best practice for managing gems in Rails projects (including the Rails gem itself) is to use Bundler . Bundler's Gemfile will list all the gems your project uses, and allows you to "pin" versions, so by changing the version pin for Rails and running bundle you can update your project to the new version.

<sarcasm> Now that I've said that, though, Bundler is probably on the way out to be replaced by something else. </sarcasm>

You still have both versions, as the other answers have mentioned. However, you don't want to call rails newapp and then change the config/environment.rb file. This will cause problems for any files that have changed between versions. Instead, create a new 2.3.5 app this way:

rails _2.3.5_ newapp

And you'll run the exact version of rails you want, to create the file structure correctly. I don't know why this isn't documented better.

To answer your question, you can install many versions of the rails gem without conflict. However, each project is created using a specific version. To install a new version of the rails gem as follow; Change the version 3.2.18 with any version you like (see link below for all available versions).

gem install rails --version=3.2.18

To install the latest version

gem install rails

To check all the rails version available, check out this link

Here is a link to all the version of rails

You might consider updating your gem software by this command prior to loading new gems.

gem update --system

As per @pjmorse, list the version installed with this command

gem list rails

Hope that helps

您可以在config/enviroment.rb定义应用程序的Rails版本。

You can vendor the version of rails you want into your vendor/rails folder. At the command line just run rake `rake rails:freeze:edge RELEASE=2.2.2'. You don't need any version of rails installed for this to work it will take the source and build it from the remote source in your vendor directory.

rake rails:freeze:edge RELEASE=2.2.1
rake rails:freeze:edge RELEASE=2.2.2
rake rails:freeze:edge RELEASE=2.2.3
rake rails:freeze:edge RELEASE=2.2.4
rake rails:freeze:edge RELEASE=2.2.5
rake rails:freeze:edge RELEASE=2.2.6
rake rails:freeze:edge RELEASE=2.2.7
rake rails:freeze:edge RELEASE=2.2.8

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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