RVM rails 3.2 and rails 2.3 - ruby-on-rails

Im having trouble setting up a development environment. I need some tutorial on how to install rvm with rails 3.2 and rails 2.3.14 side by side. I tried installing rvm 1.8.7 then rails 2.3.14 and rvm 1.9.3 then rails 3.2. After finishing I can't seem to create a gemset and I tried to switch rvm 1.8.7 buy when I generate(ruby script/generate) it showed me that it was not recognized.

Ideally speaking, you would want to create your gemsets before installing the rails gems. This way the two versions are segregated. I would do something like the following:
rvm --create use 1.8.7#some-gemset-name
gem install rails -v 2.3.14
That should install and use those specific versions together. Then for the newer versions
rvm --create use 1.9.3#some-other-gemset-name
gem install rails
Then you would just need to change rubies and gemsets when you need to with rvm use version#gemset-name. Another approach is to have the ruby and gemset change with each rails project by creating a .rvmrc file in the root of your rails project. The contents of that file would be similar to the following:
rvm version#gemset-name
I would also recommend checking out the RVM Docs as this is just the tip of the iceberg when working with RVM.

Related

selection of rails -package

I just installed rvm, ruby 1.9.3, rails 4.0 and rails 3.0
The problem is that I have to work with an application using ruby 1.9, and do not know how to select the right package. I would also like to know how to select a particular rails from the command line
One other thing: I can use Rails 4.0 for Ruby 1.9.3?
You shouldn't install two Rails versions together, this can lead to various strange behaviours, instead use Gemsets (decribed below).
To install specified Ruby version: rvm install 1.9.3-p385 - yes, you can even specify pathlevel.
To use that Ruby: rvm use 1.9.3-p385 - or just rvm use 1.9.3 if you don't have other 1.9.3 versions.
You should also create Gemset for your app so you won't pollute your rvm's specific ruby install with gems from other projects which you will probably create later.
To do that write rvm gemset create put_name_here, you will have now new Gemset in scope of your selected rvm's Ruby install.
To use that Gemset write rvm gemset use put_name_here. - You can also do rvm use 1.9.3#put_name_here - that will select both Ruby and Gemset with one command.
Now you can do bundle and all gems will be installed to specified Gemset under chosen Ruby version.
To make your life easier you can create in root of your app two files containing:
.ruby-version
1.9.3-p385
.ruby-gemset
put_name_here
And since then rvm should automatically change Ruby version and select specified Gemset when you will enter that directory.
To list installed Rubies and created Gemsets: rvm list and rvm gemset list (that shows Gemsets under current Ruby only).
And yes, you can use Rails 4.0 with Ruby 1.9.3
Also, you should check rvm homepage, everything is well described there.

Can't switch default version ruby for rails

I'm desperate, please help. I can't figure out how to change Ruby on Rails to run with 2.0.0, even though I think I've done everything to set 2.0.0 as the default, and rvm -list doesn't even show 1.8.7 as an option. I don't know what files I need to move/what pathways I need to change, and my attempts to uninstall rails have been unsuccessful as there's a "missingBundle" error.
$ ruby - v
returns ruby 2.0.0p247
$ rvm--default use 2.0.0
Using /Users/ericafischer-colbrie/.rvm/gems/ruby-2.0.0-p247
Then,
$ rails -s
Rails prefers to run ruby 2.0. You're running ruby 1.8.7 (2012-02-08 patchlevel 358)
[universal-darwin12.0]. Please upgrade to Ruby 1.9.3 or new to continue.
I've spent a lot of time looking at similar questions posted on stackoverflow and those solutions so far have not yielded any results.
Since you're using rvm, make sure you create a gemset and ruby-version file and install the version of rails you want to use.
E.g inside you're working dir tell rvm which ruby to use, which gemset to use, create both a gemset and ruby-version file:
rvm use ruby-2.0.0#my_cool_project --ruby-version --create
Then
gem install rails
To check run which ruby in that directory to make sure it's ruby 2 - - which rails will show you that it's using the gem of rails inside the ruby 2 my cool project gemset. Should be ok
Looks like you may have used something like sudo gem install rails.
When installing gems, you want to be sure to not use the sudo command.
Try sudo gem uninstall rails; rvm use ruby-2.0.0#myapp --create; gem install rails
Install rvm in your Macintosh
Then do rvm install 2.0.0 or rvm install version(whatever version you need)
Where ever you need a particular version of Ruby(say 2.0.0), do rvm use 2.0.0 and whichever version you need you can switch similarly.
If you are not sure how to install rvm or stuck with something else. Please see link for detailed explanation.
Updated, thanks #Momer.

Can we install two different versions of ruby and map them to respective versions of rails on the same server?

I have already installed Ruby 1.8.7 and Rails 2.3.8 which is working fine.
Now, I need to install Rails 3.2.8 in order to install a gem and my goal build the same compatible with Rails 2.3.8 based on how it is developed.
I tried installing Rails 3.2.8 using
gem install rails -v=3.2.8 -include-dependencies
but to my surprise when I checked gem list rails, it shows only Rails 2.3.8 and I'm unable to create a new app using rails 3.2.8 test.
I'm not sure but I read that Rails > 3.0 doesn't work well with Ruby 1.8.7 and needs Ruby>1.9
Rails 3.2 is compatible with Ruby 1.8.7. What you could do is have a ruby version manager like RVM or Rbenv. I use RVM but some people prefer Rbenv as it does not mess with your shell.
Using version managers will allow you to have different versions of ruby and with RVM you can create different gemsets for each specific version.
EDIT Here's the link for the release notes for rails 3.2 http://guides.rubyonrails.org/3_2_release_notes.html
EDIT
There's a couple of commands that you can use.
rvm list
will list the versions of ruby you have installed.
To install a version of ruby you'd do something like rvm install 1.9.3 to use that version you'd do something like rvm use 1.9.3 You can even specify patch levels and switch between different versions.
Now, rvm uses a concept of gemsets, to create a gemset you can set up an .rvmrc file in your project with the following command
rvm --create ruby-1.9.3-p286#some-project
it will create a set of gems called some-project where you can install whatever gem versions you want.
Notice that command can be ran from the command line as well. That will separate all the gems per project and you can switch between gemsets as you would ruby versions. Then in whichever gemset you'd just run gem install rails and the version
Your ruby version is good enough for both rails 2 & 3.
Try to create new app like below:
rails _3.2.8_ new appname

Every time I close terminal rails defaults back to 2.3.5 from 3.0.3?

I'm going through the rails by example tutorial.
Its seems that every time I close terminal rails defaults back to 2.3.5 & I have to go through the process of installing 3.0.3 every time I open the terminal?
I installed rails using: $ [sudo] gem install rails --version 3.0.3
Has anyone experienced a similar issue? I've tried googling around and searching stack to no avail.
The problem is almost-assuredly RVM interpreting 2.3.5 as your default rails version in your default gem set. I ran into this problem myself when first experimenting with RVM. Try this:
rvm --default use 1.9.2 (or whatever you want your default ruby interpreter to be)
rvm gemset create rails-3.0.3
rvm use 1.9.2#arails-3.0.3 --default
gem install rails
That will:
Set your default ruby interpreter to the desired ruby version
Create a gemset for your Rails 3.0.3 install and make it your default gemset
Install rails
Once you close the terminal and open it back up, it'll load RVM's defaults, putting you back on Rails 3.0.3 again.
Try uninstalling the rails gem:
gem uninstall rails
If you are prompted to select a version, select 2.3.5 and leave the 3.0.3 version intact.
P.S: Are you using RVM? If not, I would highly recommend it.
I've had this problem using RVM, if you're using RVM do: $rvm 1.9.2 (or whatever ruby version you installed the rails 3 gem with).
Check the output of $ ruby -v when you seem to have access to rails3 and again $ ruby -v when you can only seem to get to v2.3.5. If it shows different versions of ruby then you most likley are using RVM.
#Ads If youre using RVM and you install rails using sudo like so
$ [sudo] gem install rails --version 3.0.3
youre doing it wrong. RVM depends on you using a ruby distro that was installed by RVM into your user directory. If youre using sudo, youre installing rails gem into your system-wide ruby.
So check that youre using the right ruby version by doing 'rvm info' and then do your 'gem install rails --version 3.0.3' without sudo

Can I have/use different Versions of rails in the same machine

I am actually reading a rails book that is written for rails 2.3.5. I want to test Rails 3 beta as well. Is it possible to have such a setup in my Mac OS leopard?
I have tried with gem list -d rails. There are many versions stored in my mac but I don't know how to use different versions of rails while creating applications using rails command
While RVM is great there's no need for it in this use-case.
Install the Rails 3 gem: gem install rails—pre
Create new project: rails project_name (this will use the latest version installed)
To create projects with a specific version: rails _2.3.5_ project_name
Yes! Try rvm. It is awesome, you can have many different versions of Ruby, and for each one you can have different versions of gems. And you can run the same tests on all those versions. Isn't that cool?!
Quick How-To:
$ rvm install ruby-1.8.7 --default
$ gem install rails -v 1.0.0
$ rvm gemset create rails238
$ rvm 1.8.7#rails238
$ gem install rails -v 2.3.8
Now,
$ rvm 1.8.7
will give you ruby 1.8.7 and rails 1.0
And,
$ rvm 1.8.7#rails238
will give you ruby 1.8.7 and rails 2.3.8
You can make 2.3.8 as default one with
$ rvm use 1.8.7#rails238 --default
BTW rvm is documented really good.
The way to do this anymore is to use RVM, the Ruby Version Manager, which isolates different Ruby environments from each other.
A coworker of mine did a blog entry on setting up Rails 3 and RVM (and Ruby 1.9), which you might find interesting.

Resources