Specifying rails version to use when creating a new application
I found here an undocumented option to create a new application using an older version of Rails.
rails _2.1.0_ new myapp
Specify the rails version when creating a new rails application
You can always change it in the gemfile
gem 'rails', '~> 4.2.7.1'
then run:
cd MYAPP
bundle install
You can also do it with bundle like this. Follow this tutorial if you'd like more information
RVM switching Rails Versions
That's not a problem with RVM and Rails. Using the Gemfile is the best way to do this, IMHO! In your Gemfile, you can specify which ruby and which gemset within that ruby to use.
Set Default Ruby/Gemset --for system
First, lets establish that default ruby for the system on 5.0.0
. This will allow any new/existing Rails projects to default to this ruby version (except for those projects that override with the Gemfile):
rvm use --default 5.0.0
..and of course, if you want it fixed to a specified gemset:
rvm use --default 5.0.0@my_default_gemset
Set Default Ruby/Gemset --for Rails specific App on Gemfile
Example 1
If you want to setup your rails app to utilize the RVM gemset 2.2.1@rails_2_1_1
, similar to the RVM command below...
rvm use 2.2.1@rails_2_1_1
In your Gemfile, specify right below the source
line the following two commented lines:
source 'https://rubygems.org'
#ruby=2.2.1
#ruby-gemset=rails_2_1_1
Now, when you cd
into your rails' app directory, you should receive the following message, or similiar:
RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does
that too, you can ignore these warnings with 'rvm rvmrc warning ignore
/my/rails/app/path/Gemfile'.
To ignore the warning for all files run 'rvm rvmrc warning ignore
allGemfiles'.
You can double check your results:
rvm list gemsets
ruby-2.2.1 [ x86_64 ]
ruby-2.2.1@global [ x86_64 ]
=> ruby-2.2.1@rails_2_1_1 [ x86_64 ]
ruby-5.0.0 [ x86_64 ]
ruby-5.0.0@global [ x86_64 ]
Example 2
Another example using ruby-2.0.0-p247@rails-4.0.0
, example RVM command...
rvm use ruby-2.0.0-p247@rails-4.0.0
In your Gemfile, specify:
#ruby=2.0.0-p247
#ruby-gemset=rails-4.0.0
How to set default rails version for a project?
To use an older version than the latest you have installed, just wrap the version number in underscores:
rails _1.2.1_ myproject
Related Topics
Installing Rmagick Gem -- Can't Find Magickwand.H
Set Locale Automatically in Ruby on Rails
Ruby Converting String Encoding from Iso-8859-1 to Utf-8 Not Working
Rails Custom Validation Based on a Regex
How to Split Routes.Rb into Smaller Files
In Ruby, How to Get Instance Variables in a Hash Instead of an Array
Load Two Ruby Modules/Gems with the Same Name
How to Receive a JSON Object with Rack
How to Install Rails with Jruby
Obtaining a Facebook Auth Token for a Command-Line (Desktop) Application
Is Regexp.Last_Match Thread Safe
Missing File in Gem After Build
How to Reference a Constant in a Yaml with Rails
Rails 3 - How to Set Start Date to Date_Select Method
How to Run Ruby on Rails Applications on a Windows Box
How to Convert 270921Sec into Days + Hours + Minutes + Sec ? - Ruby