yulong#ubuntu:~$ rails -v
Rails 3.1.0
yulong#ubuntu:~$ cd four
yulong#ubuntu:~/four$ rails -v
Rails 3.1.0.rc8
yulong#ubuntu:~/four$ cd ..
yulong#ubuntu:~$ cd z
yulong#ubuntu:~/z$ rails -v
Rails 3.1.0.rc6
Use rvm on Linux/OSX and DevKit on Windows
For every project(folder) you can customize ruby and rails versions. Then rvm automatically will set all gems(libraries) for every folder accordingly to your settings.
If you just need to set Rails versions and not Ruby versions per project add the rails version to the Gemfile in each project folder
gem 'rails', '3.1.0'
and run
bundle install
Related
I currently have a Rails app running on 4.2.5, and I want to use ActionCable without having to upgrade the whole thing to the Rails 5.0.0.beta3 version and risk breaking all of the other gems.
Following guides I've seen on the internet, I've tried
gem 'actioncable', github: 'rails/actioncable'
which doesn't work because the ActionCable repo has been merged into the Rails repo. I even tried
gem 'actioncable', github: 'rails/rails'
but this doesn't seem to work of the re-numbering of the versions that happened when ActionCable merged into Rails. (The only version below 5.0.0.beta* is the 0.0.0, which seems to be an empty gem.)
I also tried setting the source to rubygems.org in hopes of finding an older pre-merged version, but was unsuccessful.
What can I do to integrate ActionCable into my 4.2.5 project without upgrading to Rails 5?
Conversely, when could we anticipate the first stable release of Rails 5? :)
You can have both GemSets, so you can use rails 4 and rails 5 whenever you want.
First, update the ruby gem manager by $ gem update --system, install Nokogiri if you haven't $ gem install nokogiri.
Now lets set your rails 4 GemSet (you might have to update ruby, it will tell you if you need to)
$ rvm use ruby-2.3.0#rails4.2 --create
$ gem install rails --version=4.2.5
$ rails -v
your rails version should be 4.2.5 at this point.
Now lets set your rails 5 GemSet
$ rvm use ruby-2.3.0#rails5.0 --create
$ gem install rails --pre
$ rails -v
your rails version should be 5 beta3 at this point.
We are done, now you only need to change between GemSets, depending on your needs, by doing this.
for rails 4 use = $ rvm use ruby-2.3.0#rails4.2
for rails 5 use = $ rvm use ruby-2.3.0#rails5.0
Now, you can use and experiment rails 5 without risking your rails 4 gems and stuff.
You can do exactly the same for other Rails versions if you want.
I have same issue,But i solved.just check this
Just try your rails console
check your rails version rails -v
may be rails (4.2.7.1)
Then you need to check gem list, i mean gem list -l
Now you can see your all gem with versions.
Then you need to instsll gem install rails -v 5.0.0beta2
once installed rails check gem list, gem list -l
Then you can see rails (5.0.0.rc2, 5.0.0.beta2, 4.2.7.1)
You successfully installed rails 5.0.0
Then you do bundle update
Update all gem and supporting rails 5.0.0,this is work for me just try this.
I am using MAC to learn RoR. The default Ruby in system is 2.0.0, and I installed the newest Ruby 2.2.1(not in System). However, when I run rails server, it uses ruby 2.0.0. How can I configure rails to make it use newer Ruby?
When I run "ruby -v" in terminal, the version is 2.2.1
I advise you to install a Ruby version manager app. I have been using RVM for a while.
With RVM you can have multiple versions of Ruby installed and select witch one is to be used by default.
Rails is a Gem that would be installed into each of the Ruby packages in separated, or you can have RVM to do the gem management for you as well.
Give it a try and let us know if you need more help.
In your Gemfile add ruby version you wanted to use. ie
ruby "2.2.1"
If you are using rvm then
>$ rvm install 2.2.1
>$ cd <app root dir>
>$ rvm install 2.2.1
>$ cd
>$ cd <app root dir>
I am using rails version 4.2.0. How can I downgrade to version 3.2.19?
I tried the following:
I opened command prompt.
I typed gem uninstall rails
Some options came for rails version then I selected my current version and pressed entered.
Then typed gem install rails -v 3.2.19 for installing this version.
I went to my Site directory and typed rails new blog
When I opened the Gemfile of blog application I found again Rails version 4.2.0 is present there.
Do:
gem uninstall rails
gem uninstall railties
Followed by:
gem install rails -v 3.2.19
To check a rails version, directly do:
rails -v
Another workaround:
add following to your Gemfile:
gem 'rails', '3.2.19'
and then run:
bundle install
Or you dont have to downgrade. You can always create a new rails app with a specific version(if that version is already installed)
rails _3.2.19_ new myApp
That is not good approach to uninstall a global version of Rails. So just create a Rails app:
rails new app
then change Rails version in its Gemfile, and issue bundle install:
cd app
sed "s/'rails', '~> 4.2.0'/'rails', '~> 3.2.19'/" -i Gemfile
bundle install
Then, I believe, you should change all the dependent packages to older versions.
I create a gemset with
$ rvm gemset create r3
$ rvm gemset use r3
$ gem install rails -v3.2.13
At this point
$ rails -v
now shows
$ Rails 3.2.13
but every time I do bundle with a project I've forked, I find that
rails -v
shows Rails 4.0.1 - which then gives issue with the project in question when running tests
(4.0.1 conflicts with 3.2.13).
My question is - if my Gemfile only has:
$ cat Gemfile
source 'https://rubygems.org'
gemspec
how is this happening? How can I make my command line ruby version stay at 3.2.13 and not switch to 4.0.1 Once it switches to 4.0.1 I seem to be stuck with that for that gemset and to create a 3.2.13 gemset I have to start over again.
Bundle works by finding the most up-to-date version of the gems that are compatible with the restrictions from the Gemfile. In this case, those restrictions are coming from the gemspec file, which presumably allows versions of Rails greater than 3.2.13. So it's picking the most up-to-date version of Rails allowed - which is 4.0.1. Your RVM configuration is not relevant here.
To lock your particular fork to Rails 3.2.13, just add the following:
gem 'rails', '3.2.13'
to the Gemfile in your fork. This will lock the local version to 3.2.13 when you run bundle.
if you wish to explicitly use different version of rails then the one that would be calculated from Gemfile then you need to use:
NOEXEC_DISABLE=1 rails ...
you can make it permanent for single shell session with:
export NOEXEC_DISABLE=1
rails ...
and to disable loading gems in versions calculated via Gemfile put it in you shell initialization file (like ~/.bash_profile or ~/.zlogin):
export NOEXEC_DISABLE=1
this happens because RVM installs gem rubygems-bundler which automatically analyzes your Gemfile when you run gem binaries and if a version specified via this file is available then it is loaded (even if it is specified only as dependency of your gems).
I have two versions of rails (2.1.0 and 2.2.2) installed in my computer.
When I create a new application, is it possible to specify that I want to use the older (2.1.0) version?
I found here an undocumented option to create a new application using an older version of Rails.
rails _2.1.0_ new myapp
Here is the command which I use normally:
rails _version_ new application_name
for example rails _7.0.4_ new my_app
Here is the list of all available rails versions so far:
http://rubygems.org/gems/rails/versions
I was having some trouble using rails _version_ new application_name (the resulting project was still generated for the newest version of Rails installed.)
After a bit of digging I found an article by Michael Trojanek with an alternative approach. This works by creating a folder with a Gemfile specifying the desired version of Rails and then using bundle exec rails... so that Bundler takes care of running the appropriate version of rails. e.g. to make a new Rails 4.2.9 projects the steps are:
mkdir myapp
cd myapp
echo "source 'https://rubygems.org'" > Gemfile
echo "gem 'rails', '4.2.9'" >> Gemfile
bundle install
bundle exec rails new . --force --skip-bundle
bundle update
As rightly pointed out by #mikej for Rails 5.0.0 or above, you should be following these steps:
Create a directory for your application along with a Gemfile to specify your desired Rails version and let bundler install the dependent gems:
$ mkdir myapp
$ cd myapp
$ echo "source 'https://rubygems.org'" > Gemfile
$ echo "gem 'rails', '5.0.0.1'" >> Gemfile
$ bundle install
Check that the correct version of rails has been installed: $ bundle exec rails -v
Now create your application, let Rails create a new Gemfile (or rather overwrite the existing one by using the --force flag) and instead of installing the bundle (--skip-bundle) update it manually:
$ bundle exec rails new . --force --skip-bundle
If you check the entry for rails in Gemfile, it should be like this:
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
You should update it to the exact version needed for the application:
gem 'rails', '5.0.0.1'
Now, the final step:
$ bundle update
There are two ways to achieve this:
one as suggested in accepted answer:
gem install rails -v 2.1.0 #only when the gem has not been installed in the desired ruby version you are using, so that you don't get error on next step
rails _2.1.0_ new my_app
and alternative method is to create gemfile with desired rails version before initializing rails project
mkdir my_app
cd my_app
echo "source 'https://rubygems.org'" > Gemfile
echo "gem 'rails', '2.1.0'" >> Gemfile
bundle install
bundle exec rails new . --force --skip-bundle
I have written about this in details in my article
You can generate the skeleton with either version and require the one you want in config/environment.rb:
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.1.2' unless defined? RAILS_GEM_VERSION
or use the "rails" command form the version you want anyway.
You should also take a look at "freezing" your Rails gems into the app. This helps a lot with deployment, specially in shared hosting environments.
Just change the RAILS_GEM_VERSION variable in config/environment.rb and issue the freeze rake task:
rake rails:freeze:gems
Please watch out which version of ruby you are using with Rails.
The command for making a new project for a specific version of Rail may not work for you. I had some issues about it. And the problem was the ruby version I have default which is 3.0.0. This version did not work with Rails 5. Then I installed ruby 2.7.5 and switched to it as default. Only then I was able to make projects both for Rails 5 and 7.
If you want the same environment with ruby 2.7.5
rvm install ruby-2.7.5
switch to this version as default
rvm --default use 2.7.5
install bundler and webpacker
gem install bundler
gem install webpacker
install lastest rails (which is 7)
gem install rails
test it
rails new test_app_6
cd test_app_6
rails s
check for localhost 3000
http://localhost:3000
then stop the server (control + c) and install Rails 5
gem install rails -v 5.2.6
test it
rails _5.2.6_ new test_app_5
cd test_app_5
rails s
check for localhost 3000
http://localhost:3000
You're set!