Create new Rails project with previous rails version - ruby-on-rails

The latest version of rails installed on my mac is 3.0.0.beta
gem list returns
rails (3.0.0.beta, 2.3.5, 2.3.4, 2.3.2, 2.2.2, 1.2.6)
I want to create a new project using version 2.3.5
So I run: rails _2.3.5_ myProject
But it returns the following error
$ rails _2.3.5_ photosbackup
/Library/Ruby/Site/1.8/rubygems.rb:777:in `report_activate_error': RubyGem version error: railties(3.0.0.beta not = 2.3.5) (Gem::LoadError)
from /Library/Ruby/Site/1.8/rubygems.rb:211:in `activate'
from /Library/Ruby/Site/1.8/rubygems.rb:1056:in `gem'
from /usr/bin/rails:18
Any idea how I can create a new project using version 2.3.5?
Thanks

I think you can just uninstall the previous Rails versions.
Which can be problematic - I have a number of Rails 2.3.5 (and earlier) apps in production that require maintenance and won't be upgraded to the new version.
So what I recommend in this situation is having a look at RVM - it lets you install and manage multiple versions of Ruby, and provides isolation between sets of Gems. I now run a Ruby 1.9.1 with Rails 3 and friends in isolation from my default system settings which let me do my day to day work.

even i had the same problem but the following command worked for me
rails 2.3.5 new myProject

Related

Use an older version of Rails with Rails 6 installed

Thank you this community for getting me started on the right path. Specifying rails version to use when creating a new application gets me close, but the differing ruby version is what is throwing me off. I'm running into an error after running rails new that I'm not sure where to begin to resolve it. I gather from the error that my command is missing a parameter, but I can't determine what it is.
Any advice?
I would like to create a rails 5.2.6 project and I'm finding consistent responses elsewhere indicating that my approach to getting a rails project created with a specific version is to:
install the rails gem with gem install rails -v 5.2.6
create a new rails project, specifying the rails version with rails _5.2.6 new appName
I think I'm on to it. Did a specific google search for compatibility of Ruby 3 with Rails 5 and appears this is the likely problem.
I've now run 'rvm install 2.7.4' then 'rvm use 2.7.4' but still seems to be using ruby 3 in the command. The new error:
user#ubuntudev:~/railsprojects$ rails _5.2.6_ new rpapitest
/home/user/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems.rb:281:in `find_spec_for_exe': can't find gem railties (= 5.2.6) with executable rails (Gem::GemNotFoundException)
from /home/user/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems.rb:300:in `activate_bin_path'
from /home/user/.rbenv/versions/3.0.0/bin/rails:23:in `<main>'
Try with rbenv global 2.7.4 if you have rbenv installed

Rails: using rails 5 and generating rails 4 template app

My machine is using Rails 5. Because some business, I must create new rails 4 application. I have using following syntax for generating rails 4 app:
rails _4.2.3_ new demoapp
Nevertheless, new application structure is built for rails 5. My question is: how can I use rails 5 for generating rails 4 structure app.
Thanks
First of all try to find out if you have that version installed. In this case, run this command:
gem list rails
You should see the list of gems you have installed on your computer that contains the word 'rails' in the name and also you will see the version (or versions) of that gems that you have installed.
Find where does it says rails and there you will find all the versions you have installed, in my case it is: rails (5.2.0, 5.1.6, 5.1.4, 5.1.3, 5.1.2, 5.1.1, 5.0.6, 5.0.3, 5.0.1, 5.0.0.1, 4.2.0)
So I can run the command rails _4.2.0_ new myapp and it will create a new app using rails 4.2.0.
If you don't have that version installed just run the command gem install rails -v 4.2.3
And there you have it.
References:
Specifying rails version to use when creating a new application
How to install a specific version of a ruby gem?

How do I change the default Rails version that gets used?

ANSWERED (other noobs should read what I did):
Thanks to those who answered, but I think I know why it had still been defaulting to the system ruby earlier. I started a shell session and installed rbenv, then install ruby-build for rbenv, then install ruby 2.1.2 and ran rbenv global 2.1.2 Then I installed the new version of rails and tried to create a new rails project.
I think the mistake was just that I hadn't started a new shell session and so it defaulted to the rails location it had when the session started, which was with the system ruby. Stupid mistake. Blah.
ORIGINAL POST:
These are my rbenv versions
system
* 2.1.2 (set by /home/ab/.rbenv/version)
and this is what I get when I run
gem list -d rails
rails (4.2.0.beta1, 4.1.1)
Author: David Heinemeier Hansson
Homepage: http://www.rubyonrails.org
License: MIT
Installed at (4.2.0.beta1): /home/ab/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0
(4.1.1): /home/ab/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0
The Hartl tutorial online uses 4.2.0beta1, so I want to use that, but when I try to make a new rails project, it defaults to 4.1.1.
Somebody from this suggested a way to change a default rails version, but the command looks in the wrong location. See here
ab#abpc:~/Code/RailsTutorial$ rails _4.2.0beta1_ -v
/usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find railties (= 4.2.0beta1) amongst [actionmailer-4.1.1, actionpack-4.1.1, actionview-4.1.1, activemodel-4.1.1, activerecord-4.1.1, activesupport-4.1.1, arel-5.0.1.20140414130214, builder-3.2.2, bundler-1.3.5, coffee-rails-4.0.1, coffee-script-2.2.0, coffee-script-source-1.7.0, diff-lcs-1.2.5, erubis-2.7.0, execjs-2.1.0, hike-1.2.3, i18n-0.6.9, jbuilder-2.0.7, jquery-rails-3.1.0, json-1.8.1, libv8-3.16.14.3-x86_64-linux, mail-2.5.4, mime-types-1.25.1, mini_portile-0.6.0, minitest-5.3.4, multi_json-1.10.1, net-http-persistent-2.9, nokogiri-1.6.2.1, polyglot-0.3.5, rack-1.5.2, rack-protection-1.5.3, rack-test-0.6.2, rails-4.1.1, railties-4.1.1, rake-10.3.2, rdoc-4.1.1, rdoc-3.9.4, ref-1.0.5, rspec-2.14.1, rspec-core-2.14.8, rspec-expectations-2.14.5, rspec-mocks-2.14.6, rspec-rails-2.14.2, sass-3.2.19, sass-rails-4.0.3, sdoc-0.4.0, sinatra-1.4.5, spring-1.1.3, sprockets-2.11.0, sprockets-rails-2.1.3, sqlite3-1.3.9, therubyracer-0.12.1, thor-0.19.1, thor-0.18.1.20140116, thread_safe-0.3.4, tilt-1.4.1, treetop-1.4.15, turbolinks-2.2.2, tzinfo-1.2.0, uglifier-2.5.0, webrat-0.7.3] (Gem::LoadError)
from /usr/lib/ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /usr/lib/ruby/1.9.1/rubygems.rb:1231:in `gem'
from /usr/local/bin/rails:22:in `<main>'
I'm still far from as knowledgeable as I'd like to be, but I can see that "rails" is defaulting to usr/lib/bin/rails and I need to reroute it to ~/.rbenv/versions/2.1.2/lib/ or somewhere around there... not entirely sure where, and I don't know how to get it to do that. Help?
It looks like you are using your system ruby v1.9.1 which is not compatible with rails 4 at all (Rails 4 requires 1.9.3 or higher).
So first you need to set your ruby version using rbenv global 2.1.2 to set it system-wide or rbenv local 2.1.2 if you just want it for this project. I'm not sure if your system will then default to rails-4.1.1 or the newer beta but you can try rails -v to find out. If not, rails _4.2.0.beta1_ new myapp should work.
The Hartl tutorial online uses 4.2.0beta1
Here is what I am seeing:
Install Rails
Once you’ve installed RubyGems, installing Rails should be easy. This
tutorial standardizes on Rails 4.0, which we can install as follows:
$ gem install rails --version 4.0.8
...
but when I try to make a new rails project, it defaults to 4.1.1.
Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=sample_app2_gems
gem 'rails', '4.0.8'
...
Set the version of rails you want to use in your Gemfile.

Changing default rails in ubuntu

I am working on Ubuntu . Initially I have 3 version of rails installed 3.2.9 , 3.2.12 and 4.0.0 . Running rail -v was showing Rails 4.0.0 . I tried to uninstall Rails 4.0.0 using gem uninstall rails 4.0.0 . Now Running gem uninstall rails gives this output:
Select gem to uninstall:
1. rails-3.2.9
2. rails-3.2.12
Running rails -v now also gives Rails 4.0.0 .Any guesses how can i change default rail to 3.2.12.
Investigating more on Thaha kp comment, I found this:
rails _3.2.12_ new myapp # slightly different version positioning
that means, you can install as many rails versions you want in one ruby environment, and when you start a new app you just need to specify what version to use.
Now if you started your app in rails 3.2.10 and want to upgrade to rails 3.2.11 you just change the version in your Gemfile as Bharath Sankar suggested, after a running bundle your app will use 3.2.12 version.

Cannot create new rails 3.2.6 site

I have installed ruby 1.9.3p194. I have also installed rails 3.2.8,3.2.6,and 3.0.3. I am able to create a new site using rails versions 3.2.8 and 3.0.3. When I try to create a site with rails 3.2.6 it rails to work.
rails _3.2.6_ new example
/Users/Dave/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems.rb:317:in `bin_path': can't find gem rails (["3.2.6"]) with executable rails (Gem::GemNotFoundException)
from /Users/Dave/.rvm/gems/ruby-1.9.3-p194/bin/rails:19:in `<main>'
from /Users/Dave/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `eval'
from /Users/Dave/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `<main>'
I have tried uninstalling 3.2.6 and reinstalling but the result is the same. Any help would on this would be great.
UPDATE: I was able to solve this problem by uninstalling both 3.2.6 and 3.0.3 and then reinstalling 3.2.6. Not sure why this worked but it does. At some point I need to install 3.0.3 can these versions not co-exist?
After spending some time looking at gemsets that was definitely the solution to this problem. I set up RVM and installed two versions of Ruby. Then I setup gemsets for each version that had the version of rails I needed to write code for the book I was working through and the web server I am using.

Resources