How to set default rails version for a project? - ruby-on-rails

I have installed two different rails versions in my system (Fedora).
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/")
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?

To use an older version than the latest you have installed, just wrap the version number in underscores:
rails _1.2.1_ myproject

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)
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

The URL you posted solves your problem - you simply forgot the underscores.
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

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:
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:
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.
This is my gems folder's contents:
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:
rvm use 1.9.3#global
and you can see previous Rails and Ruby versions :)
Good luck

To create a project with the specific rails version use the below command:
similar to matkins suggested
rails _5.0.7.2_ new <project_name>

In your config/environment.rb file, place this at the beginning for the old version:
RAILS_GEM_VERSION = '1.2.1'
or this for the new version:
RAILS_GEM_VERSION = '3.0.5'

here is a general format example. feel free to modify as needed
rvm use ruby-2.1.0#rails4.2

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

Related

How update the ruby version on a old rails project

I have a rails 3 app that was made with 2.0.0-p0 ruby.
Now i would like to update just the ruby to 2.2.2
I changed already the local and global ruby on rbenv to 2.2.2.
There is a way or i have to keep using the 2.0.0-p0 on this app?
You have switched to another version of Ruby and you are probably using a different gemset (probably an empty one). Try running:
bundle install
Note that after switching to a newer version of Ruby, some of your old code might not be compatible, i.e. need debugging.
Hope this help!

Can I use different version of rails for different projects directory in Windows?

Currently Rails 4.0.2 is installed in my Windows machine and I'm using it for several rails projects. But, I do want to use Rails 3.2.8 version for another project.
So, my question: Can I specify the version 3.2.8 on a single project and retain 4.0.2 in all the rest by ensuring all dependencies for 3.2.8 are installed?
Yes !
Install the rails 3.2.8 gem.
Then, you can specify which version of rails you want to use :
rails _3.2.18_ new mySuperSecretProject
In each project, you can use rails _xxx_ console, but it is easier do directly use the binstubs : bin/rails console
Yes you could do it as Intrepidd stated.
Another way to do this is by including a specific gem version in your application Gemfile and then do a bundle install. This will tell the application to use that particular version of rails over your system version
Rails can be installed as follows:
1) Specify the rails gem version in your project Gemfile
gem 'rails','3.2.8' OR gem 'rails', '4.0.2'
2) Try running bundle install. it will automatically install required rails version for you and will create a bundle unique for the project you are in.
3) For rails 4.0.2 project: if rails 3.2.8 is already installed, try running 'bundle update rails' to upgrade the current rails version and it will install all of its dependencies in the corresponding bundle.
If you want to run these projects in different ruby versions, then in Linux platforms RVM is the best option. But, in windows RVM will not work. A good option will be the Pik tool. Pik is a tool to manage multiple versions of ruby on Windows.
Please refer here for the same. Hope it helps :)

Ruby On Rails 3.2.13 - Using Different Gemsets For Rails Applications

I currently have several Rails applications running version 3.2.13 that use Ruby 1.9.3. I plan to eventually upgrade my current applications to Rails 4.0 then upgrade Ruby to 2.0. I need to time the conversion to Ruby 2.0 carefully since from my understanding Phusion Passenger will only handle one version of Ruby without some nose bleeding solutions which I do not plan to attempt to implement at this point.
I currently use one gemset for all my Rails applications. I would like to convert my Rails applications one by one from 3.2.13 to the current version of Rails 4.0 at some point. When I have tried to update one of my applications to a newer version of Rails I was told I had to do a update rails command.
What I want to do is to be able to run some of my applications using Rails 3.2.13 and others using Rails 4.0 until I am sure they will all run properly under Rails 4.0. Once I do this I will review the differences between Ruby 1.9.3 (if any) and upgrade all of them to use Rails 2.0. At this point I understand that I would just create the gemset for 2.0.0 or whatever the latest stable version of Ruby 2 is.
I have done web searches and checked the RVM website. I understand how the gemsets are assigned to the version of Ruby you want to run. However I'm not seeing anything about using gemsets with the same version of Ruby but using different versions of Rails or other combinations of gems on the same machine for different applications. Can this be done?
Any help would be appreciated.
Take a closer look! ;)
First, create a new gemset with a name corresponding to your project
https://rvm.io/gemsets/creating/
ex: rvm gemset create project_name
Then create/edit .rvmrc file in project directory: rvm use 1.9.3#project_name
One pitfall is that if you execute following commands
cd some_project
cd ../other_project
and other_project doesn't have gemset specified you'll stay in some_project gemset. To avoid that you can create .rvmrc file with default gemset in your "projects" directory (if you have one)
Project Folder
|___Gemfile
|__.ruby-gemset
|__.ruby-version
Gemfile with all the required gems mention in your project folder
.ruby-gemset should have gem set name like sample-gemset
.ruby-version file should have specific ruby version (e.g 2.0)
rvm gemset list
it will show gem set created with sample-gemset and do the
bundle install
which will install all the specific gems for this project under sample-gemset,
same you can do for other project to create other gem set, in this way you can maintain different rails/gems and ruby version for different projects with rvm.
Your Gemfile.lock nails down which version of every gem you use - you don't need to worry about gemsets.
bundle install will always install the correct versions and your app will always use the versions in Gemfile.lock, even if there are other versions floating around

How do I switch to older versions of the ruby/rails environment?

I'm trying to keep along with the Tekpub Build your own blog on rails screencast. I'm still very much a ruby novice and the problem is that I have Rails 3 installed while Rob uses an older version (Of the top of my head: version 2.3.2).
I know how to get that version of rails with gem install rails --version=2.3.2 but when I type rails new the version of the application is rails 3. How do I make this particular app work with the older version? I know this has something to do with rvm but I have no idea how to do anything but the basic rvm use operation.
Try,
rvm use <ruby version>
rvm gemset create rails2.3.2
rvm <ruby version>#rails2.3.2
gem install rails --version=2.3.2
Finally the syntax to create a new rails app in older versions of rails was just:
rails <appanme>
For more information about gemsets:
RVM: Named Gem Sets
This will install Ruby 1.8.7 and then create a gemset that will contain only a specific set of gems:
rvm install 1.8.7
rvm --create use 1.8.7#old_rails
gem install rails --version=2.3.2
Whenever you want to use this after the first time just:
rvm use 1.8.7#old_rails
.rvmrc files are really useful for automatically managing different sets of Ruby versions and gems. If you create file called .rvmrc in the project directory and put this line in it:
rvm --create use 1.8.7#old_rails
Then every time you cd into that directory RVM will switch to Ruby 1.8.7 and the gemset "old_rails". Have a look at the docs for .rvmrc here: http://rvm.beginrescueend.com/workflow/rvmrc/
Of course you can change "1.8.7" for "1.8.6", "1.8.7-p249", "ree-1.8.7-2010.02" or any other Ruby version you like, I just assumed that you would want 1.8.7.
Have a look at RVM (Ruby Version Manager)

How can I create previous version rails in rails 3?

I've just upgraded my rails version to rails 3.0.
But suddenly I need a new rails app with old version of rails.
I know the new version of rails change command line usage with rails new.
How can I create an old version of Rails in this new Rails 3 environment?
Use the following command:
rails _2.3.5_ new APP_NAME
This will create a rails project with version 2.3.5
Leonid Shevtsov provided instructions for how to do this here.
The easiest way to do it was:
Create the directory for the project
Create a Gemfile there containing
gem "rails", "2.3.9"
gem "sqlite3-ruby", :require => "sqlite3"
Runbundle install
Run bundle exec rails . to create an app in the current path
You don't even need rvm to do this.
If you need to switch back and forth, I would recommend using RVM. You can install different versions of Ruby and each can have its own set of gems. I use my system installed ruby (1.8.6?) on my Mac for Rails 2 dev, and then I installed Ruby 1.9.2 with RVM for my Rails 3 dev. Its as simple as doing this after you have RVM installed:
#install and use 1.9.2 for Rails 3
rvm install 1.9.2
rvm 1.9.2
rails new whatever
#switch back to system installed ruby for Rails 2
rvm system
rails whatever

Resources